@react-native-gpui/haptic-feedback 0.0.0-stage → 3.0.0-alpha.1
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/desktop/Cargo.toml +14 -0
- package/desktop/build.rs +3 -0
- package/desktop/src/lib.rs +66 -0
- package/package.json +35 -4
- package/react-native.config.js +9 -0
- package/src/NativeRNHapticFeedback.ts +31 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@react-native-gpui/haptic-feedback` are listed here. Each version's section becomes the notes of its GitHub release.
|
|
4
|
+
|
|
5
|
+
## 3.0.0-alpha.1 - 2026-11-27
|
|
6
|
+
|
|
7
|
+
- First release, for `react-native-haptic-feedback` 3.0.x: plays the haptic feedback of the trackpad on macOS. Windows and Linux have no haptic hardware, so the calls do nothing there.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Streetwriters
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @react-native-gpui/haptic-feedback
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adapter for [`react-native-haptic-feedback`](https://github.com/mkuczera/react-native-haptic-feedback) (MIT): plays the haptic feedback of the trackpad on macOS. Windows and Linux have no haptic hardware, so the calls do nothing there.
|
|
4
|
+
|
|
5
|
+
## About
|
|
6
|
+
|
|
7
|
+
This package is the desktop adapter for [`react-native-haptic-feedback`](https://github.com/mkuczera/react-native-haptic-feedback) 3.0. Install the original library next to it; its JavaScript runs unchanged on desktop, and this package provides the native side. The upstream library is licensed under the MIT license.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install react-native-haptic-feedback @react-native-gpui/haptic-feedback
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The module is autolinked on desktop.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
|
21
|
+
|
|
22
|
+
ReactNativeHapticFeedback.trigger('impactLight');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Platforms
|
|
26
|
+
|
|
27
|
+
macOS is tested. Windows and Linux are not tested yet.
|
|
28
|
+
|
|
29
|
+
## Limitations
|
|
30
|
+
|
|
31
|
+
Vibration patterns (`triggerPattern`) play their types in order without the timing between them. `playAHAP` rejects, since AHAP files are Apple Core Haptics only. `getSystemHapticStatus` reports `vibrationEnabled` and a `null` ringer mode.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT. See [LICENSE](LICENSE). The upstream library, [`react-native-haptic-feedback`](https://github.com/mkuczera/react-native-haptic-feedback), is MIT licensed.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "rn-gpui-haptic-feedback"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
rn-gpui-module = { version = "0.1" }
|
|
8
|
+
|
|
9
|
+
[target.'cfg(target_os = "macos")'.dependencies]
|
|
10
|
+
objc2 = "0.6"
|
|
11
|
+
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSHapticFeedback"] }
|
|
12
|
+
|
|
13
|
+
[build-dependencies]
|
|
14
|
+
rn-gpui-module-build = { version = "0.1" }
|
package/desktop/build.rs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
rn_gpui_module::include_specs!();
|
|
2
|
+
|
|
3
|
+
use rn_gpui_module::{ModuleError, ModuleThread, Value};
|
|
4
|
+
|
|
5
|
+
pub struct RNHapticFeedback;
|
|
6
|
+
|
|
7
|
+
#[cfg(target_os = "macos")]
|
|
8
|
+
fn perform(pattern: &str) {
|
|
9
|
+
use objc2_app_kit::{NSHapticFeedbackManager, NSHapticFeedbackPattern, NSHapticFeedbackPerformanceTime, NSHapticFeedbackPerformer};
|
|
10
|
+
|
|
11
|
+
let pattern = match pattern {
|
|
12
|
+
"selection" | "rigid" | "contextClick" | "textHandleMove" | "gestureStart" => {
|
|
13
|
+
NSHapticFeedbackPattern::Alignment
|
|
14
|
+
}
|
|
15
|
+
"notificationSuccess" | "notificationWarning" | "notificationError" | "confirm" | "reject" => {
|
|
16
|
+
NSHapticFeedbackPattern::LevelChange
|
|
17
|
+
}
|
|
18
|
+
_ => NSHapticFeedbackPattern::Generic,
|
|
19
|
+
};
|
|
20
|
+
let performer = NSHapticFeedbackManager::defaultPerformer();
|
|
21
|
+
performer.performFeedbackPattern_performanceTime(pattern, NSHapticFeedbackPerformanceTime::Default);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[cfg(not(target_os = "macos"))]
|
|
25
|
+
fn perform(_pattern: &str) {}
|
|
26
|
+
|
|
27
|
+
impl NativeRNHapticFeedbackSpec for RNHapticFeedback {
|
|
28
|
+
const THREAD: ModuleThread = ModuleThread::Main;
|
|
29
|
+
|
|
30
|
+
fn new(_events: NativeRNHapticFeedbackEvents) -> Self {
|
|
31
|
+
Self
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn trigger(&self, r#type: String, _options: Option<TriggerOptions>) {
|
|
35
|
+
perform(&r#type);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn stop(&self) {}
|
|
39
|
+
|
|
40
|
+
fn is_supported(&self) -> Result<bool, ModuleError> {
|
|
41
|
+
Ok(cfg!(target_os = "macos"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn trigger_pattern(&self, events: Vec<TriggerPatternEvents>, _options: Option<TriggerPatternOptions>) {
|
|
45
|
+
for event in events {
|
|
46
|
+
if let Some(kind) = event.r#type {
|
|
47
|
+
perform(&kind);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async fn play_ahap(&self, _file_name: String) -> Result<(), ModuleError> {
|
|
53
|
+
Err(ModuleError::new("AHAP playback is not available on desktop"))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async fn get_system_haptic_status(&self) -> Result<Value, ModuleError> {
|
|
57
|
+
Ok(Value::object([
|
|
58
|
+
("vibrationEnabled", Value::Bool(cfg!(target_os = "macos"))),
|
|
59
|
+
("ringerMode", Value::Null),
|
|
60
|
+
]))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
pub fn rn_gpui_register() {
|
|
65
|
+
rn_gpui_module::register(native_rn_haptic_feedback_module::<RNHapticFeedback>());
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-gpui/haptic-feedback",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
|
+
"description": "Adapter for react-native-haptic-feedback (MIT): plays the macOS haptic feedback of the trackpad",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"desktop",
|
|
10
|
+
"react-native.config.js",
|
|
11
|
+
"README.md",
|
|
12
|
+
"CHANGELOG.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"codegenConfig": {
|
|
16
|
+
"name": "RNHapticFeedbackSpec",
|
|
17
|
+
"type": "modules",
|
|
18
|
+
"jsSrcsDir": "src"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react-native": "0.87.x",
|
|
22
|
+
"react-native-haptic-feedback": "3.0.x"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
|
|
27
|
+
"directory": "modules/haptic-feedback"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/haptic-feedback#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"tag": "latest"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
trigger(
|
|
6
|
+
type: string,
|
|
7
|
+
options?: {
|
|
8
|
+
enableVibrateFallback?: boolean;
|
|
9
|
+
ignoreAndroidSystemSettings?: boolean;
|
|
10
|
+
},
|
|
11
|
+
): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
isSupported(): boolean;
|
|
14
|
+
triggerPattern(
|
|
15
|
+
events: ReadonlyArray<{
|
|
16
|
+
time: number;
|
|
17
|
+
type?: string;
|
|
18
|
+
duration?: number;
|
|
19
|
+
intensity?: number;
|
|
20
|
+
sharpness?: number;
|
|
21
|
+
}>,
|
|
22
|
+
options?: {
|
|
23
|
+
enableVibrateFallback?: boolean;
|
|
24
|
+
ignoreAndroidSystemSettings?: boolean;
|
|
25
|
+
},
|
|
26
|
+
): void;
|
|
27
|
+
playAHAP(fileName: string): Promise<void>;
|
|
28
|
+
getSystemHapticStatus(): Promise<Object>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('RNHapticFeedback');
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|