@flare-engine/haptics 0.4.18 → 0.4.19
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/dist/context.d.mts +9 -0
- package/dist/context.d.mts.map +1 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +16 -0
- package/dist/context.js.map +1 -0
- package/dist/context.mjs +15 -0
- package/dist/context.mjs.map +1 -0
- package/dist/expo.d.mts +61 -0
- package/dist/expo.d.mts.map +1 -0
- package/dist/expo.d.ts +61 -0
- package/dist/expo.d.ts.map +1 -0
- package/dist/expo.js +70 -0
- package/dist/expo.js.map +1 -0
- package/dist/expo.mjs +70 -0
- package/dist/expo.mjs.map +1 -0
- package/dist/index.d.mts +5 -128
- package/dist/index.d.ts +5 -128
- package/dist/index.js +10 -205
- package/dist/index.mjs +4 -199
- package/dist/provider.d.mts +44 -0
- package/dist/provider.d.mts.map +1 -0
- package/dist/provider.d.ts +44 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +63 -0
- package/dist/provider.js.map +1 -0
- package/dist/provider.mjs +61 -0
- package/dist/provider.mjs.map +1 -0
- package/dist/web.d.mts +19 -0
- package/dist/web.d.mts.map +1 -0
- package/dist/web.d.ts +19 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +66 -0
- package/dist/web.js.map +1 -0
- package/dist/web.mjs +66 -0
- package/dist/web.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HapticsProvider } from "./provider.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* React context carrying the active `HapticsProvider`. Defaults to
|
|
4
|
+
* `NoopHapticsProvider`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HapticsContext: import("react").Context<HapticsProvider>;
|
|
7
|
+
/** Hook returning the current `HapticsProvider`. */
|
|
8
|
+
export declare function useHaptics(): HapticsProvider;
|
|
9
|
+
//# sourceMappingURL=context.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.mts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;qBAOa,gCAAc,QAAA;;wBAGX,cAAc"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HapticsProvider } from "./provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* React context carrying the active `HapticsProvider`. Defaults to
|
|
4
|
+
* `NoopHapticsProvider`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const HapticsContext: import("react").Context<HapticsProvider>;
|
|
7
|
+
/** Hook returning the current `HapticsProvider`. */
|
|
8
|
+
export declare function useHaptics(): HapticsProvider;
|
|
9
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;qBAOa,gCAAc,QAAA;;wBAGX,cAAc"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_provider = require("./provider.js");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
// src/context.ts
|
|
4
|
+
/**
|
|
5
|
+
* React context carrying the active `HapticsProvider`. Defaults to
|
|
6
|
+
* `NoopHapticsProvider`.
|
|
7
|
+
*/
|
|
8
|
+
const HapticsContext = /* @__PURE__ */ (0, react.createContext)(require_provider.NoopHapticsProvider);
|
|
9
|
+
/** Hook returning the current `HapticsProvider`. */
|
|
10
|
+
function useHaptics() {
|
|
11
|
+
return (0, react.useContext)(HapticsContext);
|
|
12
|
+
}
|
|
13
|
+
exports.HapticsContext = HapticsContext;
|
|
14
|
+
exports.useHaptics = useHaptics;
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","NoopHapticsProvider","useContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = /* @__PURE__ */ createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n"],"mappings":";;;;;;;AAOA,MAAa,iBAAiCA,iBAAAA,GAAAA,MAAAA,cAAAA,CAA+BC,iBAAAA,mBAAmB;;AAGhG,SAAgB,aAA8B;CAC5C,QAAA,GAAOC,MAAAA,WAAAA,CAAW,cAAc;AAClC"}
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NoopHapticsProvider } from "./provider.mjs";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
// src/context.ts
|
|
4
|
+
/**
|
|
5
|
+
* React context carrying the active `HapticsProvider`. Defaults to
|
|
6
|
+
* `NoopHapticsProvider`.
|
|
7
|
+
*/
|
|
8
|
+
const HapticsContext = /* @__PURE__ */ createContext(NoopHapticsProvider);
|
|
9
|
+
/** Hook returning the current `HapticsProvider`. */
|
|
10
|
+
function useHaptics() {
|
|
11
|
+
return useContext(HapticsContext);
|
|
12
|
+
}
|
|
13
|
+
export { HapticsContext, useHaptics };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport { type HapticsProvider, NoopHapticsProvider } from './provider.js';\n\n/**\n * React context carrying the active `HapticsProvider`. Defaults to\n * `NoopHapticsProvider`.\n */\nexport const HapticsContext = /* @__PURE__ */ createContext<HapticsProvider>(NoopHapticsProvider);\n\n/** Hook returning the current `HapticsProvider`. */\nexport function useHaptics(): HapticsProvider {\n return useContext(HapticsContext);\n}\n"],"mappings":";;;;;;;AAOA,MAAa,iBAAiC,8BAA+B,mBAAmB;;AAGhG,SAAgB,aAA8B;CAC5C,OAAO,WAAW,cAAc;AAClC"}
|
package/dist/expo.d.mts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HapticsProvider } from "./provider.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Structural shape of the `expo-haptics` module surface this adapter needs — the
|
|
4
|
+
* `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared
|
|
5
|
+
* here so the package never depends on `expo-haptics`; the app injects the real
|
|
6
|
+
* module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).
|
|
7
|
+
*
|
|
8
|
+
* Style / type params are `string` because expo types them as its own string
|
|
9
|
+
* enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal
|
|
10
|
+
* this package's `HapticImpactStyle` / `HapticNotificationType` literals
|
|
11
|
+
* (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through
|
|
12
|
+
* unchanged and the real `Haptics` module stays structurally assignable.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExpoHapticsModule {
|
|
15
|
+
impactAsync(style?: string): Promise<void>;
|
|
16
|
+
notificationAsync(type?: string): Promise<void>;
|
|
17
|
+
selectionAsync(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Android system haptic feedback. Optional, so a module without it still fits.
|
|
20
|
+
* `type` is `string` for the same reason as above: expo types it as its
|
|
21
|
+
* `AndroidHaptics` string enum, and method syntax keeps the real module
|
|
22
|
+
* structurally assignable. The adapter passes that enum's values
|
|
23
|
+
* (`'clock-tick'`, `'confirm'`, …).
|
|
24
|
+
*/
|
|
25
|
+
performAndroidHapticsAsync?(type: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** Options for {@link createExpoHapticsProvider}. */
|
|
28
|
+
export interface ExpoHapticsOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The running platform — pass `Platform.OS` from `react-native`. With
|
|
31
|
+
* `'android'`, cues use the system haptic effects when the injected module has
|
|
32
|
+
* `performAndroidHapticsAsync`. The hint is needed because expo's function
|
|
33
|
+
* resolves without doing anything on other platforms, so its presence alone
|
|
34
|
+
* cannot pick the route.
|
|
35
|
+
*/
|
|
36
|
+
platform?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
|
|
40
|
+
* Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
|
|
41
|
+
* `notification` → `notificationAsync`, `selection` → `selectionAsync`); an
|
|
42
|
+
* omitted style / type forwards `undefined`, letting expo apply its own default.
|
|
43
|
+
* Starts enabled — gate it off via `setEnabled(false)` (e.g. from the
|
|
44
|
+
* `@flare-engine/a11y` reduced-motion signal, or a user setting).
|
|
45
|
+
*
|
|
46
|
+
* With `options.platform === 'android'` and a module that has
|
|
47
|
+
* `performAndroidHapticsAsync`, cues play Android system haptic effects instead:
|
|
48
|
+
* `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,
|
|
49
|
+
* `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;
|
|
50
|
+
* `notification` `success` (and omitted) → `'confirm'`, `warning` →
|
|
51
|
+
* `'long-press'`, `error` → `'reject'`. If the module rejects an effect
|
|
52
|
+
* (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo
|
|
53
|
+
* call above, and the provider stops trying that effect.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* import * as Haptics from 'expo-haptics';
|
|
57
|
+
* import { Platform } from 'react-native';
|
|
58
|
+
* const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });
|
|
59
|
+
*/
|
|
60
|
+
export declare function createExpoHapticsProvider(expo: ExpoHapticsModule, options?: ExpoHapticsOptions): HapticsProvider;
|
|
61
|
+
//# sourceMappingURL=expo.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.d.mts","names":[],"sources":["../src/expo.ts"],"mappings":";;;;;;;;;;;;;iBAmBiB;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;EAQlB,4BAA4B,eAAe;;;iBAI5B;;;;;;;;EAQf;;;;;;;;;;;;;;;;;;;;;;;;wBAyCc,0BACd,MAAM,mBACN,UAAU,qBACT"}
|
package/dist/expo.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HapticsProvider } from "./provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Structural shape of the `expo-haptics` module surface this adapter needs — the
|
|
4
|
+
* `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared
|
|
5
|
+
* here so the package never depends on `expo-haptics`; the app injects the real
|
|
6
|
+
* module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).
|
|
7
|
+
*
|
|
8
|
+
* Style / type params are `string` because expo types them as its own string
|
|
9
|
+
* enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal
|
|
10
|
+
* this package's `HapticImpactStyle` / `HapticNotificationType` literals
|
|
11
|
+
* (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through
|
|
12
|
+
* unchanged and the real `Haptics` module stays structurally assignable.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExpoHapticsModule {
|
|
15
|
+
impactAsync(style?: string): Promise<void>;
|
|
16
|
+
notificationAsync(type?: string): Promise<void>;
|
|
17
|
+
selectionAsync(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Android system haptic feedback. Optional, so a module without it still fits.
|
|
20
|
+
* `type` is `string` for the same reason as above: expo types it as its
|
|
21
|
+
* `AndroidHaptics` string enum, and method syntax keeps the real module
|
|
22
|
+
* structurally assignable. The adapter passes that enum's values
|
|
23
|
+
* (`'clock-tick'`, `'confirm'`, …).
|
|
24
|
+
*/
|
|
25
|
+
performAndroidHapticsAsync?(type: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** Options for {@link createExpoHapticsProvider}. */
|
|
28
|
+
export interface ExpoHapticsOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The running platform — pass `Platform.OS` from `react-native`. With
|
|
31
|
+
* `'android'`, cues use the system haptic effects when the injected module has
|
|
32
|
+
* `performAndroidHapticsAsync`. The hint is needed because expo's function
|
|
33
|
+
* resolves without doing anything on other platforms, so its presence alone
|
|
34
|
+
* cannot pick the route.
|
|
35
|
+
*/
|
|
36
|
+
platform?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
|
|
40
|
+
* Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
|
|
41
|
+
* `notification` → `notificationAsync`, `selection` → `selectionAsync`); an
|
|
42
|
+
* omitted style / type forwards `undefined`, letting expo apply its own default.
|
|
43
|
+
* Starts enabled — gate it off via `setEnabled(false)` (e.g. from the
|
|
44
|
+
* `@flare-engine/a11y` reduced-motion signal, or a user setting).
|
|
45
|
+
*
|
|
46
|
+
* With `options.platform === 'android'` and a module that has
|
|
47
|
+
* `performAndroidHapticsAsync`, cues play Android system haptic effects instead:
|
|
48
|
+
* `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,
|
|
49
|
+
* `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;
|
|
50
|
+
* `notification` `success` (and omitted) → `'confirm'`, `warning` →
|
|
51
|
+
* `'long-press'`, `error` → `'reject'`. If the module rejects an effect
|
|
52
|
+
* (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo
|
|
53
|
+
* call above, and the provider stops trying that effect.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* import * as Haptics from 'expo-haptics';
|
|
57
|
+
* import { Platform } from 'react-native';
|
|
58
|
+
* const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });
|
|
59
|
+
*/
|
|
60
|
+
export declare function createExpoHapticsProvider(expo: ExpoHapticsModule, options?: ExpoHapticsOptions): HapticsProvider;
|
|
61
|
+
//# sourceMappingURL=expo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.d.ts","names":[],"sources":["../src/expo.ts"],"mappings":";;;;;;;;;;;;;iBAmBiB;EACf,YAAY,iBAAiB;EAC7B,kBAAkB,gBAAgB;EAClC,kBAAkB;;;;;;;;EAQlB,4BAA4B,eAAe;;;iBAI5B;;;;;;;;EAQf;;;;;;;;;;;;;;;;;;;;;;;;wBAyCc,0BACd,MAAM,mBACN,UAAU,qBACT"}
|
package/dist/expo.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const require_provider = require("./provider.js");
|
|
2
|
+
// src/expo.ts
|
|
3
|
+
const ANDROID_SELECTION = "clock-tick";
|
|
4
|
+
const ANDROID_IMPACT = {
|
|
5
|
+
light: "keyboard-tap",
|
|
6
|
+
soft: "keyboard-tap",
|
|
7
|
+
medium: "virtual-key",
|
|
8
|
+
heavy: "long-press",
|
|
9
|
+
rigid: "long-press"
|
|
10
|
+
};
|
|
11
|
+
const ANDROID_NOTIFICATION = {
|
|
12
|
+
success: "confirm",
|
|
13
|
+
warning: "long-press",
|
|
14
|
+
error: "reject"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
|
|
18
|
+
* Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
|
|
19
|
+
* `notification` → `notificationAsync`, `selection` → `selectionAsync`); an
|
|
20
|
+
* omitted style / type forwards `undefined`, letting expo apply its own default.
|
|
21
|
+
* Starts enabled — gate it off via `setEnabled(false)` (e.g. from the
|
|
22
|
+
* `@flare-engine/a11y` reduced-motion signal, or a user setting).
|
|
23
|
+
*
|
|
24
|
+
* With `options.platform === 'android'` and a module that has
|
|
25
|
+
* `performAndroidHapticsAsync`, cues play Android system haptic effects instead:
|
|
26
|
+
* `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,
|
|
27
|
+
* `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;
|
|
28
|
+
* `notification` `success` (and omitted) → `'confirm'`, `warning` →
|
|
29
|
+
* `'long-press'`, `error` → `'reject'`. If the module rejects an effect
|
|
30
|
+
* (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo
|
|
31
|
+
* call above, and the provider stops trying that effect.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import * as Haptics from 'expo-haptics';
|
|
35
|
+
* import { Platform } from 'react-native';
|
|
36
|
+
* const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });
|
|
37
|
+
*/
|
|
38
|
+
function createExpoHapticsProvider(expo, options) {
|
|
39
|
+
if (options?.platform !== "android" || typeof expo.performAndroidHapticsAsync !== "function") return require_provider.createGatedProvider({
|
|
40
|
+
impact: (style) => expo.impactAsync(style),
|
|
41
|
+
notification: (type) => expo.notificationAsync(type),
|
|
42
|
+
selection: () => expo.selectionAsync()
|
|
43
|
+
}, true);
|
|
44
|
+
const perform = expo.performAndroidHapticsAsync.bind(expo);
|
|
45
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
46
|
+
const playSystemEffect = async (type) => {
|
|
47
|
+
if (unsupported.has(type)) return false;
|
|
48
|
+
try {
|
|
49
|
+
await perform(type);
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
unsupported.add(type);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return require_provider.createGatedProvider({
|
|
57
|
+
async impact(style) {
|
|
58
|
+
if (!await playSystemEffect(ANDROID_IMPACT[style ?? "medium"])) await expo.impactAsync(style);
|
|
59
|
+
},
|
|
60
|
+
async notification(type) {
|
|
61
|
+
if (!await playSystemEffect(ANDROID_NOTIFICATION[type ?? "success"])) await expo.notificationAsync(type);
|
|
62
|
+
},
|
|
63
|
+
async selection() {
|
|
64
|
+
if (!await playSystemEffect(ANDROID_SELECTION)) await expo.selectionAsync();
|
|
65
|
+
}
|
|
66
|
+
}, true);
|
|
67
|
+
}
|
|
68
|
+
exports.createExpoHapticsProvider = createExpoHapticsProvider;
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=expo.js.map
|
package/dist/expo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.js","names":["createGatedProvider"],"sources":["../src/expo.ts"],"sourcesContent":["import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n} from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n /**\n * Android system haptic feedback. Optional, so a module without it still fits.\n * `type` is `string` for the same reason as above: expo types it as its\n * `AndroidHaptics` string enum, and method syntax keeps the real module\n * structurally assignable. The adapter passes that enum's values\n * (`'clock-tick'`, `'confirm'`, …).\n */\n performAndroidHapticsAsync?(type: string): Promise<void>;\n}\n\n/** Options for {@link createExpoHapticsProvider}. */\nexport interface ExpoHapticsOptions {\n /**\n * The running platform — pass `Platform.OS` from `react-native`. With\n * `'android'`, cues use the system haptic effects when the injected module has\n * `performAndroidHapticsAsync`. The hint is needed because expo's function\n * resolves without doing anything on other platforms, so its presence alone\n * cannot pick the route.\n */\n platform?: string;\n}\n\nconst ANDROID_SELECTION = 'clock-tick';\n\nconst ANDROID_IMPACT: Readonly<Record<HapticImpactStyle, string>> = {\n light: 'keyboard-tap',\n soft: 'keyboard-tap',\n medium: 'virtual-key',\n heavy: 'long-press',\n rigid: 'long-press',\n};\n\nconst ANDROID_NOTIFICATION: Readonly<Record<HapticNotificationType, string>> = {\n success: 'confirm',\n warning: 'long-press',\n error: 'reject',\n};\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * With `options.platform === 'android'` and a module that has\n * `performAndroidHapticsAsync`, cues play Android system haptic effects instead:\n * `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,\n * `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;\n * `notification` `success` (and omitted) → `'confirm'`, `warning` →\n * `'long-press'`, `error` → `'reject'`. If the module rejects an effect\n * (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo\n * call above, and the provider stops trying that effect.\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * import { Platform } from 'react-native';\n * const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });\n */\nexport function createExpoHapticsProvider(\n expo: ExpoHapticsModule,\n options?: ExpoHapticsOptions,\n): HapticsProvider {\n if (options?.platform !== 'android' || typeof expo.performAndroidHapticsAsync !== 'function') {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n }\n\n const perform = expo.performAndroidHapticsAsync.bind(expo);\n const unsupported = new Set<string>();\n\n // Resolves `true` when the system effect played, `false` when the caller must\n // fall back. Any rejection marks the type: the module's error class is not\n // visible from here, and a type that failed once is not worth a retry per cue.\n const playSystemEffect = async (type: string): Promise<boolean> => {\n if (unsupported.has(type)) return false;\n try {\n await perform(type);\n return true;\n } catch {\n unsupported.add(type);\n return false;\n }\n };\n\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n if (!(await playSystemEffect(ANDROID_IMPACT[style ?? 'medium']))) {\n await expo.impactAsync(style);\n }\n },\n async notification(type): Promise<void> {\n if (!(await playSystemEffect(ANDROID_NOTIFICATION[type ?? 'success']))) {\n await expo.notificationAsync(type);\n }\n },\n async selection(): Promise<void> {\n if (!(await playSystemEffect(ANDROID_SELECTION))) await expo.selectionAsync();\n },\n },\n true,\n );\n}\n"],"mappings":";;AA6CA,MAAM,oBAAoB;AAE1B,MAAM,iBAA8D;CAClE,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;AACT;AAEA,MAAM,uBAAyE;CAC7E,SAAS;CACT,SAAS;CACT,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,0BACd,MACA,SACiB;CACjB,IAAI,SAAS,aAAa,aAAa,OAAO,KAAK,+BAA+B,YAChF,OAAOA,iBAAAA,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;CAGF,MAAM,UAAU,KAAK,2BAA2B,KAAK,IAAI;CACzD,MAAM,8BAAc,IAAI,IAAY;CAKpC,MAAM,mBAAmB,OAAO,SAAmC;EACjE,IAAI,YAAY,IAAI,IAAI,GAAG,OAAO;EAClC,IAAI;GACF,MAAM,QAAQ,IAAI;GAClB,OAAO;EACT,QAAQ;GACN,YAAY,IAAI,IAAI;GACpB,OAAO;EACT;CACF;CAEA,OAAOA,iBAAAA,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,IAAI,CAAE,MAAM,iBAAiB,eAAe,SAAS,SAAS,GAC5D,MAAM,KAAK,YAAY,KAAK;EAEhC;EACA,MAAM,aAAa,MAAqB;GACtC,IAAI,CAAE,MAAM,iBAAiB,qBAAqB,QAAQ,UAAU,GAClE,MAAM,KAAK,kBAAkB,IAAI;EAErC;EACA,MAAM,YAA2B;GAC/B,IAAI,CAAE,MAAM,iBAAiB,iBAAiB,GAAI,MAAM,KAAK,eAAe;EAC9E;CACF,GACA,IACF;AACF"}
|
package/dist/expo.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createGatedProvider } from "./provider.mjs";
|
|
2
|
+
// src/expo.ts
|
|
3
|
+
const ANDROID_SELECTION = "clock-tick";
|
|
4
|
+
const ANDROID_IMPACT = {
|
|
5
|
+
light: "keyboard-tap",
|
|
6
|
+
soft: "keyboard-tap",
|
|
7
|
+
medium: "virtual-key",
|
|
8
|
+
heavy: "long-press",
|
|
9
|
+
rigid: "long-press"
|
|
10
|
+
};
|
|
11
|
+
const ANDROID_NOTIFICATION = {
|
|
12
|
+
success: "confirm",
|
|
13
|
+
warning: "long-press",
|
|
14
|
+
error: "reject"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
|
|
18
|
+
* Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
|
|
19
|
+
* `notification` → `notificationAsync`, `selection` → `selectionAsync`); an
|
|
20
|
+
* omitted style / type forwards `undefined`, letting expo apply its own default.
|
|
21
|
+
* Starts enabled — gate it off via `setEnabled(false)` (e.g. from the
|
|
22
|
+
* `@flare-engine/a11y` reduced-motion signal, or a user setting).
|
|
23
|
+
*
|
|
24
|
+
* With `options.platform === 'android'` and a module that has
|
|
25
|
+
* `performAndroidHapticsAsync`, cues play Android system haptic effects instead:
|
|
26
|
+
* `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,
|
|
27
|
+
* `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;
|
|
28
|
+
* `notification` `success` (and omitted) → `'confirm'`, `warning` →
|
|
29
|
+
* `'long-press'`, `error` → `'reject'`. If the module rejects an effect
|
|
30
|
+
* (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo
|
|
31
|
+
* call above, and the provider stops trying that effect.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import * as Haptics from 'expo-haptics';
|
|
35
|
+
* import { Platform } from 'react-native';
|
|
36
|
+
* const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });
|
|
37
|
+
*/
|
|
38
|
+
function createExpoHapticsProvider(expo, options) {
|
|
39
|
+
if (options?.platform !== "android" || typeof expo.performAndroidHapticsAsync !== "function") return createGatedProvider({
|
|
40
|
+
impact: (style) => expo.impactAsync(style),
|
|
41
|
+
notification: (type) => expo.notificationAsync(type),
|
|
42
|
+
selection: () => expo.selectionAsync()
|
|
43
|
+
}, true);
|
|
44
|
+
const perform = expo.performAndroidHapticsAsync.bind(expo);
|
|
45
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
46
|
+
const playSystemEffect = async (type) => {
|
|
47
|
+
if (unsupported.has(type)) return false;
|
|
48
|
+
try {
|
|
49
|
+
await perform(type);
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
unsupported.add(type);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return createGatedProvider({
|
|
57
|
+
async impact(style) {
|
|
58
|
+
if (!await playSystemEffect(ANDROID_IMPACT[style ?? "medium"])) await expo.impactAsync(style);
|
|
59
|
+
},
|
|
60
|
+
async notification(type) {
|
|
61
|
+
if (!await playSystemEffect(ANDROID_NOTIFICATION[type ?? "success"])) await expo.notificationAsync(type);
|
|
62
|
+
},
|
|
63
|
+
async selection() {
|
|
64
|
+
if (!await playSystemEffect(ANDROID_SELECTION)) await expo.selectionAsync();
|
|
65
|
+
}
|
|
66
|
+
}, true);
|
|
67
|
+
}
|
|
68
|
+
export { createExpoHapticsProvider };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=expo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.mjs","names":[],"sources":["../src/expo.ts"],"sourcesContent":["import {\n createGatedProvider,\n type HapticImpactStyle,\n type HapticNotificationType,\n type HapticsProvider,\n} from './provider.js';\n\n/**\n * Structural shape of the `expo-haptics` module surface this adapter needs — the\n * `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared\n * here so the package never depends on `expo-haptics`; the app injects the real\n * module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).\n *\n * Style / type params are `string` because expo types them as its own string\n * enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal\n * this package's `HapticImpactStyle` / `HapticNotificationType` literals\n * (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through\n * unchanged and the real `Haptics` module stays structurally assignable.\n */\nexport interface ExpoHapticsModule {\n impactAsync(style?: string): Promise<void>;\n notificationAsync(type?: string): Promise<void>;\n selectionAsync(): Promise<void>;\n /**\n * Android system haptic feedback. Optional, so a module without it still fits.\n * `type` is `string` for the same reason as above: expo types it as its\n * `AndroidHaptics` string enum, and method syntax keeps the real module\n * structurally assignable. The adapter passes that enum's values\n * (`'clock-tick'`, `'confirm'`, …).\n */\n performAndroidHapticsAsync?(type: string): Promise<void>;\n}\n\n/** Options for {@link createExpoHapticsProvider}. */\nexport interface ExpoHapticsOptions {\n /**\n * The running platform — pass `Platform.OS` from `react-native`. With\n * `'android'`, cues use the system haptic effects when the injected module has\n * `performAndroidHapticsAsync`. The hint is needed because expo's function\n * resolves without doing anything on other platforms, so its presence alone\n * cannot pick the route.\n */\n platform?: string;\n}\n\nconst ANDROID_SELECTION = 'clock-tick';\n\nconst ANDROID_IMPACT: Readonly<Record<HapticImpactStyle, string>> = {\n light: 'keyboard-tap',\n soft: 'keyboard-tap',\n medium: 'virtual-key',\n heavy: 'long-press',\n rigid: 'long-press',\n};\n\nconst ANDROID_NOTIFICATION: Readonly<Record<HapticNotificationType, string>> = {\n success: 'confirm',\n warning: 'long-press',\n error: 'reject',\n};\n\n/**\n * Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.\n * Maps the cue surface onto expo's calls (`impact` → `impactAsync`,\n * `notification` → `notificationAsync`, `selection` → `selectionAsync`); an\n * omitted style / type forwards `undefined`, letting expo apply its own default.\n * Starts enabled — gate it off via `setEnabled(false)` (e.g. from the\n * `@flare-engine/a11y` reduced-motion signal, or a user setting).\n *\n * With `options.platform === 'android'` and a module that has\n * `performAndroidHapticsAsync`, cues play Android system haptic effects instead:\n * `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,\n * `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;\n * `notification` `success` (and omitted) → `'confirm'`, `warning` →\n * `'long-press'`, `error` → `'reject'`. If the module rejects an effect\n * (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo\n * call above, and the provider stops trying that effect.\n *\n * @example\n * import * as Haptics from 'expo-haptics';\n * import { Platform } from 'react-native';\n * const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });\n */\nexport function createExpoHapticsProvider(\n expo: ExpoHapticsModule,\n options?: ExpoHapticsOptions,\n): HapticsProvider {\n if (options?.platform !== 'android' || typeof expo.performAndroidHapticsAsync !== 'function') {\n return createGatedProvider(\n {\n impact: (style) => expo.impactAsync(style),\n notification: (type) => expo.notificationAsync(type),\n selection: () => expo.selectionAsync(),\n },\n true,\n );\n }\n\n const perform = expo.performAndroidHapticsAsync.bind(expo);\n const unsupported = new Set<string>();\n\n // Resolves `true` when the system effect played, `false` when the caller must\n // fall back. Any rejection marks the type: the module's error class is not\n // visible from here, and a type that failed once is not worth a retry per cue.\n const playSystemEffect = async (type: string): Promise<boolean> => {\n if (unsupported.has(type)) return false;\n try {\n await perform(type);\n return true;\n } catch {\n unsupported.add(type);\n return false;\n }\n };\n\n return createGatedProvider(\n {\n async impact(style): Promise<void> {\n if (!(await playSystemEffect(ANDROID_IMPACT[style ?? 'medium']))) {\n await expo.impactAsync(style);\n }\n },\n async notification(type): Promise<void> {\n if (!(await playSystemEffect(ANDROID_NOTIFICATION[type ?? 'success']))) {\n await expo.notificationAsync(type);\n }\n },\n async selection(): Promise<void> {\n if (!(await playSystemEffect(ANDROID_SELECTION))) await expo.selectionAsync();\n },\n },\n true,\n );\n}\n"],"mappings":";;AA6CA,MAAM,oBAAoB;AAE1B,MAAM,iBAA8D;CAClE,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;AACT;AAEA,MAAM,uBAAyE;CAC7E,SAAS;CACT,SAAS;CACT,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,0BACd,MACA,SACiB;CACjB,IAAI,SAAS,aAAa,aAAa,OAAO,KAAK,+BAA+B,YAChF,OAAO,oBACL;EACE,SAAS,UAAU,KAAK,YAAY,KAAK;EACzC,eAAe,SAAS,KAAK,kBAAkB,IAAI;EACnD,iBAAiB,KAAK,eAAe;CACvC,GACA,IACF;CAGF,MAAM,UAAU,KAAK,2BAA2B,KAAK,IAAI;CACzD,MAAM,8BAAc,IAAI,IAAY;CAKpC,MAAM,mBAAmB,OAAO,SAAmC;EACjE,IAAI,YAAY,IAAI,IAAI,GAAG,OAAO;EAClC,IAAI;GACF,MAAM,QAAQ,IAAI;GAClB,OAAO;EACT,QAAQ;GACN,YAAY,IAAI,IAAI;GACpB,OAAO;EACT;CACF;CAEA,OAAO,oBACL;EACE,MAAM,OAAO,OAAsB;GACjC,IAAI,CAAE,MAAM,iBAAiB,eAAe,SAAS,SAAS,GAC5D,MAAM,KAAK,YAAY,KAAK;EAEhC;EACA,MAAM,aAAa,MAAqB;GACtC,IAAI,CAAE,MAAM,iBAAiB,qBAAqB,QAAQ,UAAU,GAClE,MAAM,KAAK,kBAAkB,IAAI;EAErC;EACA,MAAM,YAA2B;GAC/B,IAAI,CAAE,MAAM,iBAAiB,iBAAiB,GAAI,MAAM,KAAK,eAAe;EAC9E;CACF,GACA,IACF;AACF"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,128 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Haptics (tactile feedback) provider interface. Consumers supply a concrete
|
|
7
|
-
* adapter (Expo Haptics, the Web Vibration API, a Core Haptics bridge) at the app
|
|
8
|
-
* boundary. The cue surface is deliberately thin — three semantic calls mirroring
|
|
9
|
-
* the iOS `UIFeedbackGenerator` family so any platform SDK can back it — plus an
|
|
10
|
-
* enabled gate, so the user's haptics setting and the reduced-motion gate
|
|
11
|
-
* (`@flare-engine/a11y`) live in one place instead of at every call site.
|
|
12
|
-
*/
|
|
13
|
-
interface HapticsProvider {
|
|
14
|
-
/** A physical impact cue — weapon fire, projectile hit, bomb detonation. */
|
|
15
|
-
impact(style?: HapticImpactStyle): Promise<void>;
|
|
16
|
-
/** A notification cue — victory, medal earned, error / deny. */
|
|
17
|
-
notification(type?: HapticNotificationType): Promise<void>;
|
|
18
|
-
/** A light selection tick — menu focus, toggle, pickup. */
|
|
19
|
-
selection(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Whether cues currently fire. Reflects the user setting and the reduced-motion
|
|
22
|
-
* gate; when `false`, `impact` / `notification` / `selection` are no-ops.
|
|
23
|
-
*/
|
|
24
|
-
isEnabled(): boolean;
|
|
25
|
-
/** Enable or disable all feedback. When disabled, cue methods resolve without firing. */
|
|
26
|
-
setEnabled(enabled: boolean): void;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Immutable no-op provider. Reports disabled and fires nothing — the safe default
|
|
30
|
-
* where there is no haptics backend (web without vibration, CI, tests) and the
|
|
31
|
-
* default value of `HapticsContext`. `setEnabled` is inert BY DESIGN: this is the
|
|
32
|
-
* hard "off" default, so wiring it into a context can never accidentally report
|
|
33
|
-
* "enabled". For a no-op whose enabled toggle is observable (e.g. to unit-test a
|
|
34
|
-
* consumer's haptics setting), use {@link createNoopHapticsProvider}.
|
|
35
|
-
*/
|
|
36
|
-
export declare const NoopHapticsProvider: HapticsProvider;
|
|
37
|
-
/**
|
|
38
|
-
* Create a stateful no-op provider: cue methods never fire, but `setEnabled` /
|
|
39
|
-
* `isEnabled` track real state. Use it to unit-test a consumer's haptics toggle
|
|
40
|
-
* without a native backend. Each call is an independent instance; defaults to
|
|
41
|
-
* disabled (matching {@link NoopHapticsProvider}).
|
|
42
|
-
*/
|
|
43
|
-
export declare function createNoopHapticsProvider(initialEnabled?: boolean): HapticsProvider;
|
|
44
|
-
/**
|
|
45
|
-
* React context carrying the active `HapticsProvider`. Defaults to
|
|
46
|
-
* `NoopHapticsProvider`.
|
|
47
|
-
*/
|
|
48
|
-
export declare const HapticsContext: import("react").Context<HapticsProvider>;
|
|
49
|
-
/** Hook returning the current `HapticsProvider`. */
|
|
50
|
-
export declare function useHaptics(): HapticsProvider;
|
|
51
|
-
/**
|
|
52
|
-
* Structural shape of the `expo-haptics` module surface this adapter needs — the
|
|
53
|
-
* `impactAsync` / `notificationAsync` / `selectionAsync` async calls. Declared
|
|
54
|
-
* here so the package never depends on `expo-haptics`; the app injects the real
|
|
55
|
-
* module (matching the repo's adapter pattern — cf. `@flare-engine/iap-revenuecat`).
|
|
56
|
-
*
|
|
57
|
-
* Style / type params are `string` because expo types them as its own string
|
|
58
|
-
* enums (`ImpactFeedbackStyle` / `NotificationFeedbackType`) whose VALUES equal
|
|
59
|
-
* this package's `HapticImpactStyle` / `HapticNotificationType` literals
|
|
60
|
-
* (`'light'`…`'rigid'`, `'success'`…`'error'`), so the cue kind forwards through
|
|
61
|
-
* unchanged and the real `Haptics` module stays structurally assignable.
|
|
62
|
-
*/
|
|
63
|
-
interface ExpoHapticsModule {
|
|
64
|
-
impactAsync(style?: string): Promise<void>;
|
|
65
|
-
notificationAsync(type?: string): Promise<void>;
|
|
66
|
-
selectionAsync(): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Android system haptic feedback. Optional, so a module without it still fits.
|
|
69
|
-
* `type` is `string` for the same reason as above: expo types it as its
|
|
70
|
-
* `AndroidHaptics` string enum, and method syntax keeps the real module
|
|
71
|
-
* structurally assignable. The adapter passes that enum's values
|
|
72
|
-
* (`'clock-tick'`, `'confirm'`, …).
|
|
73
|
-
*/
|
|
74
|
-
performAndroidHapticsAsync?(type: string): Promise<void>;
|
|
75
|
-
}
|
|
76
|
-
/** Options for {@link createExpoHapticsProvider}. */
|
|
77
|
-
interface ExpoHapticsOptions {
|
|
78
|
-
/**
|
|
79
|
-
* The running platform — pass `Platform.OS` from `react-native`. With
|
|
80
|
-
* `'android'`, cues use the system haptic effects when the injected module has
|
|
81
|
-
* `performAndroidHapticsAsync`. The hint is needed because expo's function
|
|
82
|
-
* resolves without doing anything on other platforms, so its presence alone
|
|
83
|
-
* cannot pick the route.
|
|
84
|
-
*/
|
|
85
|
-
platform?: string;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a {@link HapticsProvider} backed by an injected `expo-haptics` module.
|
|
89
|
-
* Maps the cue surface onto expo's calls (`impact` → `impactAsync`,
|
|
90
|
-
* `notification` → `notificationAsync`, `selection` → `selectionAsync`); an
|
|
91
|
-
* omitted style / type forwards `undefined`, letting expo apply its own default.
|
|
92
|
-
* Starts enabled — gate it off via `setEnabled(false)` (e.g. from the
|
|
93
|
-
* `@flare-engine/a11y` reduced-motion signal, or a user setting).
|
|
94
|
-
*
|
|
95
|
-
* With `options.platform === 'android'` and a module that has
|
|
96
|
-
* `performAndroidHapticsAsync`, cues play Android system haptic effects instead:
|
|
97
|
-
* `selection` → `'clock-tick'`; `impact` `light` / `soft` → `'keyboard-tap'`,
|
|
98
|
-
* `medium` (and omitted) → `'virtual-key'`, `heavy` / `rigid` → `'long-press'`;
|
|
99
|
-
* `notification` `success` (and omitted) → `'confirm'`, `warning` →
|
|
100
|
-
* `'long-press'`, `error` → `'reject'`. If the module rejects an effect
|
|
101
|
-
* (`'confirm'` / `'reject'` need Android 11), that cue falls back to the expo
|
|
102
|
-
* call above, and the provider stops trying that effect.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* import * as Haptics from 'expo-haptics';
|
|
106
|
-
* import { Platform } from 'react-native';
|
|
107
|
-
* const haptics = createExpoHapticsProvider(Haptics, { platform: Platform.OS });
|
|
108
|
-
*/
|
|
109
|
-
export declare function createExpoHapticsProvider(expo: ExpoHapticsModule, options?: ExpoHapticsOptions): HapticsProvider;
|
|
110
|
-
/** Structural shape of `navigator.vibrate`: buzz for `ms`, or run an on/off pattern; returns whether it fired. */
|
|
111
|
-
type WebVibrate = (pattern: number | number[]) => boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Create a {@link HapticsProvider} backed by the Web Vibration API. Pass
|
|
114
|
-
* `navigator.vibrate` bound to `navigator` (e.g.
|
|
115
|
-
* `navigator.vibrate?.bind(navigator)`).
|
|
116
|
-
*
|
|
117
|
-
* When `vibrate` is absent — the API is unsupported on iOS Safari and most
|
|
118
|
-
* desktop browsers — this returns the inert {@link NoopHapticsProvider}, so
|
|
119
|
-
* `isEnabled()` stays `false` and cues never fire (callers need not feature-detect,
|
|
120
|
-
* and the provider never claims to be enabled when there is no backend). When
|
|
121
|
-
* present, starts enabled; gate via `setEnabled`.
|
|
122
|
-
*
|
|
123
|
-
* Cue durations: impact scales with intensity, notification uses a distinct pulse
|
|
124
|
-
* pattern per category, selection is a single short tick.
|
|
125
|
-
*/
|
|
126
|
-
export declare function createWebVibrationProvider(vibrate?: WebVibrate): HapticsProvider;
|
|
127
|
-
export type { ExpoHapticsModule, ExpoHapticsOptions, HapticImpactStyle, HapticNotificationType, HapticsProvider, WebVibrate };
|
|
128
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { HapticsContext, useHaptics } from "./context.mjs";
|
|
2
|
+
import { ExpoHapticsModule, ExpoHapticsOptions, createExpoHapticsProvider } from "./expo.mjs";
|
|
3
|
+
import { HapticImpactStyle, HapticNotificationType, HapticsProvider, NoopHapticsProvider, createNoopHapticsProvider } from "./provider.mjs";
|
|
4
|
+
import { WebVibrate, createWebVibrationProvider } from "./web.mjs";
|
|
5
|
+
export { type ExpoHapticsModule, type ExpoHapticsOptions, type HapticImpactStyle, type HapticNotificationType, HapticsContext, type HapticsProvider, NoopHapticsProvider, type WebVibrate, createExpoHapticsProvider, createNoopHapticsProvider, createWebVibrationProvider, useHaptics };
|