james-rn-haptic-feedback 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/RnHapticFeedback.podspec +20 -0
- package/android/build.gradle +67 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rnhapticfeedback/HapticPatternModule.kt +59 -0
- package/ios/HapticPattern.swift +62 -0
- package/lib/module/NativeHapticPattern.js +8 -0
- package/lib/module/NativeHapticPattern.js.map +1 -0
- package/lib/module/index.js +53 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeHapticPattern.d.ts +14 -0
- package/lib/typescript/src/NativeHapticPattern.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +12 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +169 -0
- package/src/NativeHapticPattern.ts +22 -0
- package/src/index.tsx +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JinwooPark
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# james-rn-haptic-feedback
|
|
2
|
+
|
|
3
|
+
It is for haptic feedback.haptic
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install james-rn-haptic-feedback
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { multiply } from 'james-rn-haptic-feedback';
|
|
18
|
+
|
|
19
|
+
// ...
|
|
20
|
+
|
|
21
|
+
const result = multiply(3, 7);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
28
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "RnHapticFeedback"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/otterpark/james-rn-haptic-feedback.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.RnHapticFeedback = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return RnHapticFeedback[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dependencies {
|
|
23
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
24
|
+
// noinspection DifferentKotlinGradleVersion
|
|
25
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
apply plugin: "com.android.library"
|
|
31
|
+
apply plugin: "kotlin-android"
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.facebook.react"
|
|
34
|
+
|
|
35
|
+
android {
|
|
36
|
+
namespace "com.rnhapticfeedback"
|
|
37
|
+
|
|
38
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
39
|
+
|
|
40
|
+
defaultConfig {
|
|
41
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
42
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
buildFeatures {
|
|
46
|
+
buildConfig true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
buildTypes {
|
|
50
|
+
release {
|
|
51
|
+
minifyEnabled false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lint {
|
|
56
|
+
disable "GradleCompatible"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
compileOptions {
|
|
60
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
61
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dependencies {
|
|
66
|
+
implementation "com.facebook.react:react-android"
|
|
67
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import android.os.VibrationEffect
|
|
2
|
+
import android.os.Vibrator
|
|
3
|
+
import android.os.VibratorManager
|
|
4
|
+
import com.facebook.react.bridge.*
|
|
5
|
+
|
|
6
|
+
class HapticPatternModule(reactContext: ReactApplicationContext) :
|
|
7
|
+
NativeHapticPatternSpec(reactContext) {
|
|
8
|
+
|
|
9
|
+
private val vibrator: Vibrator by lazy {
|
|
10
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
11
|
+
val vm = reactContext.getSystemService(VibratorManager::class.java)
|
|
12
|
+
vm.defaultVibrator
|
|
13
|
+
} else {
|
|
14
|
+
@Suppress("DEPRECATION")
|
|
15
|
+
reactContext.getSystemService(Vibrator::class.java)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 단일 진동
|
|
20
|
+
override fun trigger(intensity: Double, duration: Double) {
|
|
21
|
+
val amplitude = (intensity * 255).toInt().coerceIn(1, 255)
|
|
22
|
+
val effect = VibrationEffect.createOneShot(
|
|
23
|
+
duration.toLong(),
|
|
24
|
+
amplitude
|
|
25
|
+
)
|
|
26
|
+
vibrator.vibrate(effect)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 패턴 시퀀스
|
|
30
|
+
override fun playPattern(steps: ReadableArray) {
|
|
31
|
+
val timings = mutableListOf<Long>()
|
|
32
|
+
val amplitudes = mutableListOf<Int>()
|
|
33
|
+
|
|
34
|
+
for (i in 0 until steps.size()) {
|
|
35
|
+
val step = steps.getMap(i)
|
|
36
|
+
val intensity = step.getDouble("intensity")
|
|
37
|
+
val duration = step.getDouble("duration").toLong()
|
|
38
|
+
val delay = if (step.hasKey("delay")) step.getDouble("delay").toLong() else 0L
|
|
39
|
+
|
|
40
|
+
if (delay > 0) {
|
|
41
|
+
timings.add(delay) // 대기 구간
|
|
42
|
+
amplitudes.add(0) // 진동 없음
|
|
43
|
+
}
|
|
44
|
+
timings.add(duration)
|
|
45
|
+
amplitudes.add((intensity * 255).toInt().coerceIn(1, 255))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
val effect = VibrationEffect.createWaveform(
|
|
49
|
+
timings.toLongArray(),
|
|
50
|
+
amplitudes.toIntArray(),
|
|
51
|
+
-1 // 반복 없음
|
|
52
|
+
)
|
|
53
|
+
vibrator.vibrate(effect)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun cancel() {
|
|
57
|
+
vibrator.cancel()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import CoreHaptics
|
|
2
|
+
|
|
3
|
+
@objc(HapticPattern)
|
|
4
|
+
class HapticPattern: NSObject {
|
|
5
|
+
private var engine: CHHapticEngine?
|
|
6
|
+
|
|
7
|
+
override init() {
|
|
8
|
+
super.init()
|
|
9
|
+
prepareEngine()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 엔진 초기화
|
|
13
|
+
private func prepareEngine() {
|
|
14
|
+
guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else { return }
|
|
15
|
+
do {
|
|
16
|
+
engine = try CHHapticEngine()
|
|
17
|
+
try engine?.start()
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 단일 진동
|
|
22
|
+
@objc func trigger(_ intensity: Double, duration: Double) {
|
|
23
|
+
playPattern([["intensity": intensity, "duration": duration]])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 패턴 시퀀스
|
|
27
|
+
@objc func playPattern(_ steps: [[String: Any]]) {
|
|
28
|
+
guard let engine else { return }
|
|
29
|
+
var events: [CHHapticEvent] = []
|
|
30
|
+
var time: Double = 0
|
|
31
|
+
|
|
32
|
+
for step in steps {
|
|
33
|
+
let intensity = step["intensity"] as? Double ?? 1.0
|
|
34
|
+
let duration = (step["duration"] as? Double ?? 100) / 1000.0
|
|
35
|
+
let delay = (step["delay"] as? Double ?? 0) / 1000.0
|
|
36
|
+
|
|
37
|
+
time += delay
|
|
38
|
+
let params = [
|
|
39
|
+
CHHapticEventParameter(parameterID: .hapticIntensity, value: Float(intensity)),
|
|
40
|
+
CHHapticEventParameter(parameterID: .hapticSharpness, value: Float(intensity))
|
|
41
|
+
]
|
|
42
|
+
events.append(CHHapticEvent(
|
|
43
|
+
eventType: .hapticContinuous,
|
|
44
|
+
parameters: params,
|
|
45
|
+
relativeTime: time,
|
|
46
|
+
duration: duration
|
|
47
|
+
))
|
|
48
|
+
time += duration
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
do {
|
|
52
|
+
let pattern = try CHHapticPattern(events: events, parameters: [])
|
|
53
|
+
let player = try engine.makePlayer(with: pattern)
|
|
54
|
+
try player.start(atTime: 0)
|
|
55
|
+
} catch {}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@objc func cancel() {
|
|
59
|
+
engine?.stop()
|
|
60
|
+
prepareEngine() // 재사용을 위해 재시작
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeHapticPattern.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;;AAElD;;AAkBA,eAAeA,mBAAmB,CAACC,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeHapticPattern from "./NativeHapticPattern.js";
|
|
4
|
+
export const HapticPattern = {
|
|
5
|
+
// 단일 진동
|
|
6
|
+
trigger: (intensity, duration) => {
|
|
7
|
+
NativeHapticPattern.trigger(intensity, duration);
|
|
8
|
+
},
|
|
9
|
+
// 패턴 시퀀스
|
|
10
|
+
playPattern: steps => {
|
|
11
|
+
NativeHapticPattern.playPattern(steps);
|
|
12
|
+
},
|
|
13
|
+
// 중단
|
|
14
|
+
cancel: () => {
|
|
15
|
+
NativeHapticPattern.cancel();
|
|
16
|
+
},
|
|
17
|
+
// 자주 쓰는 프리셋 제공
|
|
18
|
+
presets: {
|
|
19
|
+
heartbeat: () => HapticPattern.playPattern([{
|
|
20
|
+
intensity: 0.8,
|
|
21
|
+
duration: 80
|
|
22
|
+
}, {
|
|
23
|
+
intensity: 0.3,
|
|
24
|
+
duration: 50,
|
|
25
|
+
delay: 100
|
|
26
|
+
}, {
|
|
27
|
+
intensity: 0.8,
|
|
28
|
+
duration: 80,
|
|
29
|
+
delay: 400
|
|
30
|
+
}]),
|
|
31
|
+
error: () => HapticPattern.playPattern([{
|
|
32
|
+
intensity: 1.0,
|
|
33
|
+
duration: 100
|
|
34
|
+
}, {
|
|
35
|
+
intensity: 1.0,
|
|
36
|
+
duration: 100,
|
|
37
|
+
delay: 80
|
|
38
|
+
}, {
|
|
39
|
+
intensity: 1.0,
|
|
40
|
+
duration: 100,
|
|
41
|
+
delay: 80
|
|
42
|
+
}]),
|
|
43
|
+
success: () => HapticPattern.playPattern([{
|
|
44
|
+
intensity: 0.4,
|
|
45
|
+
duration: 50
|
|
46
|
+
}, {
|
|
47
|
+
intensity: 1.0,
|
|
48
|
+
duration: 150,
|
|
49
|
+
delay: 50
|
|
50
|
+
}])
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeHapticPattern","HapticPattern","trigger","intensity","duration","playPattern","steps","cancel","presets","heartbeat","delay","error","success"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,mBAAmB,MAA2B,0BAAuB;AAE5E,OAAO,MAAMC,aAAa,GAAG;EAC3B;EACAC,OAAO,EAAEA,CAACC,SAAiB,EAAEC,QAAgB,KAAK;IAChDJ,mBAAmB,CAACE,OAAO,CAACC,SAAS,EAAEC,QAAQ,CAAC;EAClD,CAAC;EAED;EACAC,WAAW,EAAGC,KAAmB,IAAK;IACpCN,mBAAmB,CAACK,WAAW,CAACC,KAAK,CAAC;EACxC,CAAC;EAED;EACAC,MAAM,EAAEA,CAAA,KAAM;IACZP,mBAAmB,CAACO,MAAM,CAAC,CAAC;EAC9B,CAAC;EAED;EACAC,OAAO,EAAE;IACPC,SAAS,EAAEA,CAAA,KAAMR,aAAa,CAACI,WAAW,CAAC,CACzC;MAAEF,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE;IAAG,CAAC,EAChC;MAAED,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE,EAAE;MAAEM,KAAK,EAAE;IAAI,CAAC,EAC5C;MAAEP,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE,EAAE;MAAEM,KAAK,EAAE;IAAI,CAAC,CAC7C,CAAC;IACFC,KAAK,EAAEA,CAAA,KAAMV,aAAa,CAACI,WAAW,CAAC,CACrC;MAAEF,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE;IAAI,CAAC,EACjC;MAAED,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE,GAAG;MAAEM,KAAK,EAAE;IAAG,CAAC,EAC5C;MAAEP,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE,GAAG;MAAEM,KAAK,EAAE;IAAG,CAAC,CAC7C,CAAC;IACFE,OAAO,EAAEA,CAAA,KAAMX,aAAa,CAACI,WAAW,CAAC,CACvC;MAAEF,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE;IAAG,CAAC,EAChC;MAAED,SAAS,EAAE,GAAG;MAAEC,QAAQ,EAAE,GAAG;MAAEM,KAAK,EAAE;IAAG,CAAC,CAC7C;EACH;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface HapticStep {
|
|
3
|
+
intensity: number;
|
|
4
|
+
duration: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Spec extends TurboModule {
|
|
8
|
+
trigger(intensity: number, duration: number): void;
|
|
9
|
+
playPattern(steps: HapticStep[]): void;
|
|
10
|
+
cancel(): void;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: Spec;
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=NativeHapticPattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeHapticPattern.d.ts","sourceRoot":"","sources":["../../../src/NativeHapticPattern.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAGnD,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAGvC,MAAM,IAAI,IAAI,CAAC;CAChB;;AAED,wBAAuE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type HapticStep } from './NativeHapticPattern';
|
|
2
|
+
export declare const HapticPattern: {
|
|
3
|
+
trigger: (intensity: number, duration: number) => void;
|
|
4
|
+
playPattern: (steps: HapticStep[]) => void;
|
|
5
|
+
cancel: () => void;
|
|
6
|
+
presets: {
|
|
7
|
+
heartbeat: () => void;
|
|
8
|
+
error: () => void;
|
|
9
|
+
success: () => void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAA4B,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE7E,eAAO,MAAM,aAAa;yBAEH,MAAM,YAAY,MAAM;yBAKxB,UAAU,EAAE;;;;;;;CA0BlC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "james-rn-haptic-feedback",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "It is for haptic feedback.haptic",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace james-rn-haptic-feedback-example",
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"release": "release-it --only-version"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/otterpark/james-rn-haptic-feedback.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "JinwooPark <otterpark94@gmail.com> (https://github.com/otterpark)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/otterpark/james-rn-haptic-feedback/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/otterpark/james-rn-haptic-feedback#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@react-native/babel-preset": "0.83.0",
|
|
67
|
+
"@react-native/eslint-config": "0.83.0",
|
|
68
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
69
|
+
"@types/jest": "^29.5.14",
|
|
70
|
+
"@types/react": "^19.2.0",
|
|
71
|
+
"commitlint": "^19.8.1",
|
|
72
|
+
"del-cli": "^6.0.0",
|
|
73
|
+
"eslint": "^9.35.0",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
76
|
+
"jest": "^29.7.0",
|
|
77
|
+
"lefthook": "^2.0.3",
|
|
78
|
+
"prettier": "^2.8.8",
|
|
79
|
+
"react": "19.2.0",
|
|
80
|
+
"react-native": "0.83.0",
|
|
81
|
+
"react-native-builder-bob": "^0.40.18",
|
|
82
|
+
"release-it": "^19.0.4",
|
|
83
|
+
"turbo": "^2.5.6",
|
|
84
|
+
"typescript": "^5.9.2"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "*",
|
|
88
|
+
"react-native": "*"
|
|
89
|
+
},
|
|
90
|
+
"workspaces": [
|
|
91
|
+
"example"
|
|
92
|
+
],
|
|
93
|
+
"packageManager": "yarn@4.11.0",
|
|
94
|
+
"react-native-builder-bob": {
|
|
95
|
+
"source": "src",
|
|
96
|
+
"output": "lib",
|
|
97
|
+
"targets": [
|
|
98
|
+
[
|
|
99
|
+
"module",
|
|
100
|
+
{
|
|
101
|
+
"esm": true
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"typescript",
|
|
106
|
+
{
|
|
107
|
+
"project": "tsconfig.build.json"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
"codegenConfig": {
|
|
113
|
+
"name": "RnHapticFeedbackSpec",
|
|
114
|
+
"type": "modules",
|
|
115
|
+
"jsSrcsDir": "src",
|
|
116
|
+
"android": {
|
|
117
|
+
"javaPackageName": "com.rnhapticfeedback"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"prettier": {
|
|
121
|
+
"quoteProps": "consistent",
|
|
122
|
+
"singleQuote": true,
|
|
123
|
+
"tabWidth": 2,
|
|
124
|
+
"trailingComma": "es5",
|
|
125
|
+
"useTabs": false
|
|
126
|
+
},
|
|
127
|
+
"jest": {
|
|
128
|
+
"preset": "react-native",
|
|
129
|
+
"modulePathIgnorePatterns": [
|
|
130
|
+
"<rootDir>/example/node_modules",
|
|
131
|
+
"<rootDir>/lib/"
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
"commitlint": {
|
|
135
|
+
"extends": [
|
|
136
|
+
"@commitlint/config-conventional"
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
"release-it": {
|
|
140
|
+
"git": {
|
|
141
|
+
"commitMessage": "chore: release ${version}",
|
|
142
|
+
"tagName": "v${version}"
|
|
143
|
+
},
|
|
144
|
+
"npm": {
|
|
145
|
+
"publish": true
|
|
146
|
+
},
|
|
147
|
+
"github": {
|
|
148
|
+
"release": true
|
|
149
|
+
},
|
|
150
|
+
"plugins": {
|
|
151
|
+
"@release-it/conventional-changelog": {
|
|
152
|
+
"preset": {
|
|
153
|
+
"name": "angular"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"create-react-native-library": {
|
|
159
|
+
"type": "turbo-module",
|
|
160
|
+
"languages": "kotlin-objc",
|
|
161
|
+
"tools": [
|
|
162
|
+
"eslint",
|
|
163
|
+
"jest",
|
|
164
|
+
"lefthook",
|
|
165
|
+
"release-it"
|
|
166
|
+
],
|
|
167
|
+
"version": "0.57.2"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
// 커스텀 패턴의 각 스텝 타입
|
|
5
|
+
export interface HapticStep {
|
|
6
|
+
intensity: number; // 0.0 ~ 1.0
|
|
7
|
+
duration: number; // milliseconds
|
|
8
|
+
delay?: number; // 다음 스텝까지 대기 시간 (ms)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Spec extends TurboModule {
|
|
12
|
+
// 단일 진동
|
|
13
|
+
trigger(intensity: number, duration: number): void;
|
|
14
|
+
|
|
15
|
+
// 패턴 시퀀스 실행
|
|
16
|
+
playPattern(steps: HapticStep[]): void;
|
|
17
|
+
|
|
18
|
+
// 진행 중인 햅틱 중단
|
|
19
|
+
cancel(): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('HapticPattern');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import NativeHapticPattern, { type HapticStep } from './NativeHapticPattern';
|
|
2
|
+
|
|
3
|
+
export const HapticPattern = {
|
|
4
|
+
// 단일 진동
|
|
5
|
+
trigger: (intensity: number, duration: number) => {
|
|
6
|
+
NativeHapticPattern.trigger(intensity, duration);
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
// 패턴 시퀀스
|
|
10
|
+
playPattern: (steps: HapticStep[]) => {
|
|
11
|
+
NativeHapticPattern.playPattern(steps);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
// 중단
|
|
15
|
+
cancel: () => {
|
|
16
|
+
NativeHapticPattern.cancel();
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// 자주 쓰는 프리셋 제공
|
|
20
|
+
presets: {
|
|
21
|
+
heartbeat: () => HapticPattern.playPattern([
|
|
22
|
+
{ intensity: 0.8, duration: 80 },
|
|
23
|
+
{ intensity: 0.3, duration: 50, delay: 100 },
|
|
24
|
+
{ intensity: 0.8, duration: 80, delay: 400 },
|
|
25
|
+
]),
|
|
26
|
+
error: () => HapticPattern.playPattern([
|
|
27
|
+
{ intensity: 1.0, duration: 100 },
|
|
28
|
+
{ intensity: 1.0, duration: 100, delay: 80 },
|
|
29
|
+
{ intensity: 1.0, duration: 100, delay: 80 },
|
|
30
|
+
]),
|
|
31
|
+
success: () => HapticPattern.playPattern([
|
|
32
|
+
{ intensity: 0.4, duration: 50 },
|
|
33
|
+
{ intensity: 1.0, duration: 150, delay: 50 },
|
|
34
|
+
]),
|
|
35
|
+
}
|
|
36
|
+
};
|