-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1446d8e
Showing
150 changed files
with
29,980 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# XDE | ||
.expo/ | ||
|
||
# VSCode | ||
.vscode/ | ||
jsconfig.json | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IJ | ||
# | ||
.classpath | ||
.cxx | ||
.gradle | ||
.idea | ||
.project | ||
.settings | ||
local.properties | ||
android.iml | ||
|
||
# Cocoapods | ||
# | ||
example/ios/Pods | ||
|
||
# Ruby | ||
example/vendor/ | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-debug.log | ||
yarn-error.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
android/app/libs | ||
android/keystores/debug.keystore | ||
|
||
# Yarn | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# Expo | ||
.expo/ | ||
|
||
# Turborepo | ||
.turbo/ | ||
|
||
# generated by bob | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 🌀 Turbo Haptics | ||
|
||
Fast, **worklet-compatible** haptic feedback for React Native. | ||
|
||
## Features | ||
|
||
- 🏎️ Zero-delay haptic feedback, powered by JSI | ||
- 🪄 Compatible with Reanimated and Gesture Handler worklets | ||
- 🎯 9 different haptic patterns (impact, notification, selection) | ||
- 📱 iOS and Android support | ||
- 🪶 Lightweight, zero dependencies | ||
|
||
## Installation | ||
|
||
```sh | ||
yarn add react-native-turbo-haptics | ||
cd ios && pod install | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { triggerHaptics } from 'react-native-turbo-haptics'; | ||
|
||
// In any JavaScript context: | ||
triggerHaptics('selection'); | ||
|
||
// In worklets: | ||
Gesture.Tap() | ||
.onBegin(() => triggerHaptics('soft')); | ||
``` | ||
|
||
```ts | ||
// Available haptic types: | ||
const HapticTypes = { | ||
impactHeavy: 'impactHeavy', | ||
impactLight: 'impactLight', | ||
impactMedium: 'impactMedium', | ||
notificationError: 'notificationError', | ||
notificationSuccess: 'notificationSuccess', | ||
notificationWarning: 'notificationWarning', | ||
rigid: 'rigid', | ||
selection: 'selection', | ||
soft: 'soft', | ||
}; | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
arrowParens: 'avoid', | ||
bracketSameLine: true, | ||
bracketSpacing: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "json" | ||
|
||
package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "TurboHaptics" | ||
s.version = package["version"] | ||
s.summary = package["description"] | ||
s.homepage = package["homepage"] | ||
s.license = package["license"] | ||
s.authors = package["author"] | ||
|
||
s.platforms = { :ios => "13.0" } | ||
s.source = { :git => "https://github.com/christianbaroni/react-native-turbo-haptics.git", :tag => "#{s.version}" } | ||
|
||
s.source_files = "ios/**/*.{h,m,mm}" | ||
|
||
install_modules_dependencies(s) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
project("turbo-haptics") | ||
|
||
add_subdirectory(src/main/jni) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
def isNewArchitectureEnabled() { | ||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
} | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
if (isNewArchitectureEnabled()) { | ||
apply plugin: 'com.facebook.react' | ||
} | ||
|
||
android { | ||
namespace "com.turbohaptics" | ||
compileSdkVersion safeExtGet('compileSdkVersion', 33) | ||
|
||
defaultConfig { | ||
minSdkVersion safeExtGet('minSdkVersion', 21) | ||
targetSdkVersion safeExtGet('targetSdkVersion', 33) | ||
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags "-std=c++17" | ||
} | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
if (isNewArchitectureEnabled()) { | ||
java.srcDirs += [ | ||
'src/fabric', | ||
// Codegen output directory | ||
project.file("${project.buildDir}/generated/source/codegen/java") | ||
] | ||
} else { | ||
java.srcDirs += ['src/paper'] | ||
} | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
path "src/main/jni/CMakeLists.txt" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib" | ||
compileOnly "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-keep class com.turbohaptics.** { *; } |
43 changes: 43 additions & 0 deletions
43
package/android/src/fabric/java/com/turbohaptics/TurboHapticsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.turbohaptics | ||
|
||
import androidx.annotation.NonNull | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.NativeModule | ||
|
||
class TurboHapticsModule(context: ReactApplicationContext) : | ||
NativeTurboHapticsSpec(context), | ||
NativeModule { | ||
|
||
companion object { | ||
const val NAME = "TurboHaptics" | ||
|
||
init { | ||
System.loadLibrary("turbo-haptics") | ||
} | ||
} | ||
|
||
override fun getName(): String = NAME | ||
|
||
override fun initialize() {} | ||
|
||
override fun invalidate() {} | ||
|
||
override fun install(): Boolean { | ||
try { | ||
val catalystInstance = reactApplicationContext.catalystInstance | ||
?: return false | ||
|
||
val runtimePointer = catalystInstance.javaScriptContextHolder.get() | ||
if (runtimePointer == 0L) { | ||
return false | ||
} | ||
|
||
return nativeInstallHaptics(runtimePointer, reactApplicationContext) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
return false | ||
} | ||
} | ||
|
||
private external fun nativeInstallHaptics(runtimePointer: Long, context: ReactApplicationContext): Boolean | ||
} |
38 changes: 38 additions & 0 deletions
38
package/android/src/fabric/java/com/turbohaptics/TurboHapticsPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.turbohaptics | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
|
||
class TurboHapticsPackage : TurboReactPackage() { | ||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
if (name == TurboHapticsModule.NAME) { | ||
return TurboHapticsModule(reactContext) | ||
} | ||
return null | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos = HashMap<String, ReactModuleInfo>() | ||
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED | ||
moduleInfos.apply { | ||
put( | ||
TurboHapticsModule.NAME, | ||
ReactModuleInfo( | ||
TurboHapticsModule.NAME, | ||
TurboHapticsModule.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
isTurboModule // isTurboModule | ||
) | ||
) | ||
} | ||
moduleInfos | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.turbohaptics"> | ||
<uses-permission android:name="android.permission.VIBRATE" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
project("turbo-haptics") | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(NODE_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../node_modules") | ||
|
||
add_library(turbo-haptics SHARED | ||
TurboHapticsHostObject.cpp | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp") | ||
|
||
target_include_directories(turbo-haptics PRIVATE | ||
"${CMAKE_CURRENT_SOURCE_DIR}/includes" | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon" | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi" | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi" | ||
) | ||
|
||
find_library(log-lib log) | ||
|
||
target_link_libraries(turbo-haptics | ||
android | ||
${log-lib}) |
Oops, something went wrong.