@flighthq/haptics 0.5.1-next.1069.554a2ac → 0.5.1-next.1201.9b49dee
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/README.md +2 -2
- package/dist/haptics.d.ts +11 -11
- package/dist/haptics.d.ts.map +1 -1
- package/dist/haptics.js +20 -20
- package/dist/haptics.js.map +1 -1
- package/package.json +2 -2
- package/src/haptics.test.ts +33 -31
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/haptics`. The `@flig
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/haptics@0.5.1-next.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/haptics@0.5.1-next.1201.9b49dee](https://github.com/flighthq/flight/tree/9b49dee3f22f6b2838c3d237edcc77bca65734f2/packages/haptics)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/9b49dee3f22f6b2838c3d237edcc77bca65734f2/LICENSE.md)
|
package/dist/haptics.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { HapticImpactStyle, HapticNotificationType, HapticsCapabilities,
|
|
2
|
-
export declare function cancelDeviceVibration(
|
|
3
|
-
export declare function getHapticsCapabilities(
|
|
4
|
-
export declare function isHapticsSupported(
|
|
5
|
-
export declare function prepareHaptics(
|
|
6
|
-
export declare function triggerHapticImpact(
|
|
7
|
-
export declare function triggerHapticNotification(
|
|
8
|
-
export declare function triggerHapticSelection(
|
|
9
|
-
export declare function vibrateDevice(
|
|
10
|
-
export declare function vibrateDevicePattern(
|
|
11
|
-
export declare function vibrateDeviceWaveform(
|
|
1
|
+
import type { HapticImpactStyle, HapticNotificationType, HapticsCapabilities, HostHapticsProvider } from '@flighthq/types/contract';
|
|
2
|
+
export declare function cancelDeviceVibration(hostHaptics: Readonly<HostHapticsProvider>): boolean;
|
|
3
|
+
export declare function getHapticsCapabilities(hostHaptics: Readonly<HostHapticsProvider>, out: HapticsCapabilities): HapticsCapabilities;
|
|
4
|
+
export declare function isHapticsSupported(hostHaptics: Readonly<HostHapticsProvider>): boolean;
|
|
5
|
+
export declare function prepareHaptics(hostHaptics: Readonly<HostHapticsProvider>): void;
|
|
6
|
+
export declare function triggerHapticImpact(hostHaptics: Readonly<HostHapticsProvider>, style: HapticImpactStyle, intensity?: number): boolean;
|
|
7
|
+
export declare function triggerHapticNotification(hostHaptics: Readonly<HostHapticsProvider>, type: HapticNotificationType): boolean;
|
|
8
|
+
export declare function triggerHapticSelection(hostHaptics: Readonly<HostHapticsProvider>): boolean;
|
|
9
|
+
export declare function vibrateDevice(hostHaptics: Readonly<HostHapticsProvider>, durationMs: number): boolean;
|
|
10
|
+
export declare function vibrateDevicePattern(hostHaptics: Readonly<HostHapticsProvider>, pattern: Readonly<number[]>): boolean;
|
|
11
|
+
export declare function vibrateDeviceWaveform(hostHaptics: Readonly<HostHapticsProvider>, timings: Readonly<number[]>, amplitudes: Readonly<number[]>, repeat?: number): boolean;
|
|
12
12
|
//# sourceMappingURL=haptics.d.ts.map
|
package/dist/haptics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"haptics.d.ts","sourceRoot":"","sources":["../src/haptics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"haptics.d.ts","sourceRoot":"","sources":["../src/haptics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAEzF;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,GAAG,EAAE,mBAAmB,GACvB,mBAAmB,CAErB;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAEtF;AAID,wBAAgB,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAE/E;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,KAAK,EAAE,iBAAiB,EACxB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAET;AAED,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAET;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAE1F;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAErG;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAGrH;AAID,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAC3B,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAC9B,MAAM,SAAK,GACV,OAAO,CAOT"}
|
package/dist/haptics.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export function cancelDeviceVibration(
|
|
2
|
-
return
|
|
1
|
+
export function cancelDeviceVibration(hostHaptics) {
|
|
2
|
+
return hostHaptics.cancel();
|
|
3
3
|
}
|
|
4
|
-
export function getHapticsCapabilities(
|
|
5
|
-
return
|
|
4
|
+
export function getHapticsCapabilities(hostHaptics, out) {
|
|
5
|
+
return hostHaptics.capabilities(out);
|
|
6
6
|
}
|
|
7
|
-
export function isHapticsSupported(
|
|
8
|
-
return
|
|
7
|
+
export function isHapticsSupported(hostHaptics) {
|
|
8
|
+
return hostHaptics.isSupported();
|
|
9
9
|
}
|
|
10
10
|
// Warm-up hint. `prepare` is optional on the backend, so a host whose provider does not pre-allocate
|
|
11
11
|
// simply does nothing here — that is the absence of a capability, not a failure.
|
|
12
|
-
export function prepareHaptics(
|
|
13
|
-
|
|
12
|
+
export function prepareHaptics(hostHaptics) {
|
|
13
|
+
hostHaptics.prepare?.();
|
|
14
14
|
}
|
|
15
|
-
export function triggerHapticImpact(
|
|
16
|
-
return
|
|
15
|
+
export function triggerHapticImpact(hostHaptics, style, intensity) {
|
|
16
|
+
return hostHaptics.impact(style, intensity ?? 1);
|
|
17
17
|
}
|
|
18
|
-
export function triggerHapticNotification(
|
|
19
|
-
return
|
|
18
|
+
export function triggerHapticNotification(hostHaptics, type) {
|
|
19
|
+
return hostHaptics.notification(type);
|
|
20
20
|
}
|
|
21
|
-
export function triggerHapticSelection(
|
|
22
|
-
return
|
|
21
|
+
export function triggerHapticSelection(hostHaptics) {
|
|
22
|
+
return hostHaptics.selection();
|
|
23
23
|
}
|
|
24
|
-
export function vibrateDevice(
|
|
25
|
-
return
|
|
24
|
+
export function vibrateDevice(hostHaptics, durationMs) {
|
|
25
|
+
return hostHaptics.vibrate(durationMs);
|
|
26
26
|
}
|
|
27
|
-
export function vibrateDevicePattern(
|
|
27
|
+
export function vibrateDevicePattern(hostHaptics, pattern) {
|
|
28
28
|
if (pattern.length === 0)
|
|
29
29
|
return false;
|
|
30
|
-
return
|
|
30
|
+
return hostHaptics.vibratePattern(pattern);
|
|
31
31
|
}
|
|
32
32
|
// Amplitude-aware waveform, falling back to a plain timing pattern when the selected provider does not
|
|
33
33
|
// implement one. The fallback drops amplitudes rather than failing: every backend can express timings.
|
|
34
|
-
export function vibrateDeviceWaveform(
|
|
35
|
-
const backend =
|
|
34
|
+
export function vibrateDeviceWaveform(hostHaptics, timings, amplitudes, repeat = -1) {
|
|
35
|
+
const backend = hostHaptics;
|
|
36
36
|
if (timings.length === 0)
|
|
37
37
|
return false;
|
|
38
38
|
if (backend.vibrateWaveform !== undefined) {
|
package/dist/haptics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"haptics.js","sourceRoot":"","sources":["../src/haptics.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,qBAAqB,CAAC,
|
|
1
|
+
{"version":3,"file":"haptics.js","sourceRoot":"","sources":["../src/haptics.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,qBAAqB,CAAC,WAA0C;IAC9E,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,WAA0C,EAC1C,GAAwB;IAExB,OAAO,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,WAA0C;IAC3E,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC;AAED,qGAAqG;AACrG,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,WAA0C;IACvE,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAA0C,EAC1C,KAAwB,EACxB,SAAkB;IAElB,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,WAA0C,EAC1C,IAA4B;IAE5B,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,WAA0C;IAC/E,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAA0C,EAAE,UAAkB;IAC1F,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,WAA0C,EAAE,OAA2B;IAC1G,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED,uGAAuG;AACvG,uGAAuG;AACvG,MAAM,UAAU,qBAAqB,CACnC,WAA0C,EAC1C,OAA2B,EAC3B,UAA8B,EAC9B,MAAM,GAAG,CAAC,CAAC;IAEX,MAAM,OAAO,GAAG,WAAW,CAAC;IAC5B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/haptics",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.1201.9b49dee",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/types": "0.5.1-next.
|
|
41
|
+
"@flighthq/types": "0.5.1-next.1201.9b49dee"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.3.0"
|
package/src/haptics.test.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
HapticImpactStyle,
|
|
3
3
|
HapticNotificationType,
|
|
4
|
-
|
|
4
|
+
HostHapticsProvider,
|
|
5
5
|
HapticsCapabilities,
|
|
6
|
-
HasInputHaptics,
|
|
7
6
|
} from '@flighthq/types/contract';
|
|
8
7
|
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
9
8
|
|
|
@@ -39,7 +38,10 @@ function makeCapabilities(overrides: Partial<HapticsCapabilities> = {}): Haptics
|
|
|
39
38
|
// A host carrying a recording haptics provider. Every operation is explicit here — there is no ambient
|
|
40
39
|
// slot to install into and nothing to reset between tests, which is the point of the migration: two
|
|
41
40
|
// tests can hold two different providers at once without interfering.
|
|
42
|
-
function makeHost(overrides: Partial<
|
|
41
|
+
function makeHost(overrides: Partial<HostHapticsProvider> = {}): {
|
|
42
|
+
calls: RecordedCall[];
|
|
43
|
+
host: { readonly input: { readonly haptics: HostHapticsProvider } };
|
|
44
|
+
} {
|
|
43
45
|
const calls: RecordedCall[] = [];
|
|
44
46
|
const record =
|
|
45
47
|
(name: string, result: boolean) =>
|
|
@@ -47,7 +49,7 @@ function makeHost(overrides: Partial<HapticsBackend> = {}): { calls: RecordedCal
|
|
|
47
49
|
calls.push({ args, name });
|
|
48
50
|
return result;
|
|
49
51
|
};
|
|
50
|
-
const haptics:
|
|
52
|
+
const haptics: HostHapticsProvider = {
|
|
51
53
|
[EntityRuntimeKey]: undefined,
|
|
52
54
|
cancel: record('cancel', true),
|
|
53
55
|
capabilities(out: HapticsCapabilities): HapticsCapabilities {
|
|
@@ -56,12 +58,12 @@ function makeHost(overrides: Partial<HapticsBackend> = {}): { calls: RecordedCal
|
|
|
56
58
|
out.supported = true;
|
|
57
59
|
return out;
|
|
58
60
|
},
|
|
59
|
-
impact: record('impact', true) as
|
|
60
|
-
isSupported: record('isSupported', true) as
|
|
61
|
-
notification: record('notification', true) as
|
|
62
|
-
selection: record('selection', true) as
|
|
63
|
-
vibrate: record('vibrate', true) as
|
|
64
|
-
vibratePattern: record('vibratePattern', true) as
|
|
61
|
+
impact: record('impact', true) as HostHapticsProvider['impact'],
|
|
62
|
+
isSupported: record('isSupported', true) as HostHapticsProvider['isSupported'],
|
|
63
|
+
notification: record('notification', true) as HostHapticsProvider['notification'],
|
|
64
|
+
selection: record('selection', true) as HostHapticsProvider['selection'],
|
|
65
|
+
vibrate: record('vibrate', true) as HostHapticsProvider['vibrate'],
|
|
66
|
+
vibratePattern: record('vibratePattern', true) as HostHapticsProvider['vibratePattern'],
|
|
65
67
|
...overrides,
|
|
66
68
|
};
|
|
67
69
|
return { calls, host: { input: { haptics } } };
|
|
@@ -70,13 +72,13 @@ function makeHost(overrides: Partial<HapticsBackend> = {}): { calls: RecordedCal
|
|
|
70
72
|
describe('cancelDeviceVibration', () => {
|
|
71
73
|
it('forwards to the selected provider', () => {
|
|
72
74
|
const { calls, host } = makeHost();
|
|
73
|
-
expect(cancelDeviceVibration(host)).toBe(true);
|
|
75
|
+
expect(cancelDeviceVibration(host.input.haptics)).toBe(true);
|
|
74
76
|
expect(calls.map((call) => call.name)).toEqual(['cancel']);
|
|
75
77
|
});
|
|
76
78
|
|
|
77
79
|
it('returns whatever the provider reports rather than assuming success', () => {
|
|
78
80
|
const { host } = makeHost({ cancel: () => false });
|
|
79
|
-
expect(cancelDeviceVibration(host)).toBe(false);
|
|
81
|
+
expect(cancelDeviceVibration(host.input.haptics)).toBe(false);
|
|
80
82
|
});
|
|
81
83
|
});
|
|
82
84
|
|
|
@@ -84,7 +86,7 @@ describe('getHapticsCapabilities', () => {
|
|
|
84
86
|
it('fills and returns the caller-owned out parameter', () => {
|
|
85
87
|
const { host } = makeHost();
|
|
86
88
|
const out = makeCapabilities();
|
|
87
|
-
expect(getHapticsCapabilities(host, out)).toBe(out);
|
|
89
|
+
expect(getHapticsCapabilities(host.input.haptics, out)).toBe(out);
|
|
88
90
|
expect(out.supported).toBe(true);
|
|
89
91
|
expect(out.patterns).toBe(true);
|
|
90
92
|
});
|
|
@@ -101,20 +103,20 @@ describe('getHapticsCapabilities', () => {
|
|
|
101
103
|
},
|
|
102
104
|
});
|
|
103
105
|
|
|
104
|
-
expect(getHapticsCapabilities(supported.host, makeCapabilities()).supported).toBe(true);
|
|
105
|
-
expect(getHapticsCapabilities(unsupported.host, makeCapabilities()).supported).toBe(false);
|
|
106
|
+
expect(getHapticsCapabilities(supported.host.input.haptics, makeCapabilities()).supported).toBe(true);
|
|
107
|
+
expect(getHapticsCapabilities(unsupported.host.input.haptics, makeCapabilities()).supported).toBe(false);
|
|
106
108
|
});
|
|
107
109
|
});
|
|
108
110
|
|
|
109
111
|
describe('isHapticsSupported', () => {
|
|
110
112
|
it('forwards to the selected provider', () => {
|
|
111
113
|
const { host } = makeHost();
|
|
112
|
-
expect(isHapticsSupported(host)).toBe(true);
|
|
114
|
+
expect(isHapticsSupported(host.input.haptics)).toBe(true);
|
|
113
115
|
});
|
|
114
116
|
|
|
115
117
|
it('reports false for a provider that says so', () => {
|
|
116
118
|
const { host } = makeHost({ isSupported: () => false });
|
|
117
|
-
expect(isHapticsSupported(host)).toBe(false);
|
|
119
|
+
expect(isHapticsSupported(host.input.haptics)).toBe(false);
|
|
118
120
|
});
|
|
119
121
|
});
|
|
120
122
|
|
|
@@ -126,7 +128,7 @@ describe('prepareHaptics', () => {
|
|
|
126
128
|
prepared = true;
|
|
127
129
|
},
|
|
128
130
|
});
|
|
129
|
-
prepareHaptics(host);
|
|
131
|
+
prepareHaptics(host.input.haptics);
|
|
130
132
|
expect(prepared).toBe(true);
|
|
131
133
|
});
|
|
132
134
|
|
|
@@ -135,27 +137,27 @@ describe('prepareHaptics', () => {
|
|
|
135
137
|
it('does nothing when the provider omits prepare', () => {
|
|
136
138
|
const { host } = makeHost();
|
|
137
139
|
expect(host.input.haptics.prepare).toBeUndefined();
|
|
138
|
-
expect(() => prepareHaptics(host)).not.toThrow();
|
|
140
|
+
expect(() => prepareHaptics(host.input.haptics)).not.toThrow();
|
|
139
141
|
});
|
|
140
142
|
});
|
|
141
143
|
|
|
142
144
|
describe('triggerHapticImpact', () => {
|
|
143
145
|
it('forwards the style and defaults intensity to 1', () => {
|
|
144
146
|
const { calls, host } = makeHost();
|
|
145
|
-
triggerHapticImpact(host, 'heavy');
|
|
147
|
+
triggerHapticImpact(host.input.haptics, 'heavy');
|
|
146
148
|
expect(calls[0]).toEqual({ args: ['heavy', 1], name: 'impact' });
|
|
147
149
|
});
|
|
148
150
|
|
|
149
151
|
it('forwards an explicit intensity unchanged', () => {
|
|
150
152
|
const { calls, host } = makeHost();
|
|
151
|
-
triggerHapticImpact(host, 'light', 0.25);
|
|
153
|
+
triggerHapticImpact(host.input.haptics, 'light', 0.25);
|
|
152
154
|
expect(calls[0]).toEqual({ args: ['light', 0.25], name: 'impact' });
|
|
153
155
|
});
|
|
154
156
|
|
|
155
157
|
it('forwards every impact style', () => {
|
|
156
158
|
const styles: readonly HapticImpactStyle[] = ['heavy', 'light', 'medium', 'rigid', 'soft'];
|
|
157
159
|
const { calls, host } = makeHost();
|
|
158
|
-
for (const style of styles) triggerHapticImpact(host, style);
|
|
160
|
+
for (const style of styles) triggerHapticImpact(host.input.haptics, style);
|
|
159
161
|
expect(calls.map((call) => call.args[0])).toEqual(styles);
|
|
160
162
|
});
|
|
161
163
|
});
|
|
@@ -164,7 +166,7 @@ describe('triggerHapticNotification', () => {
|
|
|
164
166
|
it('forwards every notification type', () => {
|
|
165
167
|
const types: readonly HapticNotificationType[] = ['error', 'success', 'warning'];
|
|
166
168
|
const { calls, host } = makeHost();
|
|
167
|
-
for (const type of types) triggerHapticNotification(host, type);
|
|
169
|
+
for (const type of types) triggerHapticNotification(host.input.haptics, type);
|
|
168
170
|
expect(calls.map((call) => call.args[0])).toEqual(types);
|
|
169
171
|
});
|
|
170
172
|
});
|
|
@@ -172,7 +174,7 @@ describe('triggerHapticNotification', () => {
|
|
|
172
174
|
describe('triggerHapticSelection', () => {
|
|
173
175
|
it('forwards to the selected provider', () => {
|
|
174
176
|
const { calls, host } = makeHost();
|
|
175
|
-
expect(triggerHapticSelection(host)).toBe(true);
|
|
177
|
+
expect(triggerHapticSelection(host.input.haptics)).toBe(true);
|
|
176
178
|
expect(calls.map((call) => call.name)).toEqual(['selection']);
|
|
177
179
|
});
|
|
178
180
|
});
|
|
@@ -180,7 +182,7 @@ describe('triggerHapticSelection', () => {
|
|
|
180
182
|
describe('vibrateDevice', () => {
|
|
181
183
|
it('forwards the duration to the selected provider', () => {
|
|
182
184
|
const { calls, host } = makeHost();
|
|
183
|
-
vibrateDevice(host, 42);
|
|
185
|
+
vibrateDevice(host.input.haptics, 42);
|
|
184
186
|
expect(calls[0]).toEqual({ args: [42], name: 'vibrate' });
|
|
185
187
|
});
|
|
186
188
|
});
|
|
@@ -188,13 +190,13 @@ describe('vibrateDevice', () => {
|
|
|
188
190
|
describe('vibrateDevicePattern', () => {
|
|
189
191
|
it('forwards a non-empty pattern', () => {
|
|
190
192
|
const { calls, host } = makeHost();
|
|
191
|
-
vibrateDevicePattern(host, [10, 20]);
|
|
193
|
+
vibrateDevicePattern(host.input.haptics, [10, 20]);
|
|
192
194
|
expect(calls[0]).toEqual({ args: [[10, 20]], name: 'vibratePattern' });
|
|
193
195
|
});
|
|
194
196
|
|
|
195
197
|
it('rejects an empty pattern before reaching the provider', () => {
|
|
196
198
|
const { calls, host } = makeHost();
|
|
197
|
-
expect(vibrateDevicePattern(host, [])).toBe(false);
|
|
199
|
+
expect(vibrateDevicePattern(host.input.haptics, [])).toBe(false);
|
|
198
200
|
expect(calls).toEqual([]);
|
|
199
201
|
});
|
|
200
202
|
});
|
|
@@ -206,8 +208,8 @@ describe('vibrateDeviceWaveform', () => {
|
|
|
206
208
|
calls.push({ args, name: 'vibrateWaveform' });
|
|
207
209
|
return true;
|
|
208
210
|
},
|
|
209
|
-
} as Partial<
|
|
210
|
-
expect(vibrateDeviceWaveform(host, [10, 20], [255, 128], 1)).toBe(true);
|
|
211
|
+
} as Partial<HostHapticsProvider>);
|
|
212
|
+
expect(vibrateDeviceWaveform(host.input.haptics, [10, 20], [255, 128], 1)).toBe(true);
|
|
211
213
|
expect(calls[0]).toEqual({ args: [[10, 20], [255, 128], 1], name: 'vibrateWaveform' });
|
|
212
214
|
});
|
|
213
215
|
|
|
@@ -216,13 +218,13 @@ describe('vibrateDeviceWaveform', () => {
|
|
|
216
218
|
it('falls back to vibratePattern with the timings when vibrateWaveform is absent', () => {
|
|
217
219
|
const { calls, host } = makeHost();
|
|
218
220
|
expect(host.input.haptics.vibrateWaveform).toBeUndefined();
|
|
219
|
-
expect(vibrateDeviceWaveform(host, [10, 20], [255, 128])).toBe(true);
|
|
221
|
+
expect(vibrateDeviceWaveform(host.input.haptics, [10, 20], [255, 128])).toBe(true);
|
|
220
222
|
expect(calls[0]).toEqual({ args: [[10, 20]], name: 'vibratePattern' });
|
|
221
223
|
});
|
|
222
224
|
|
|
223
225
|
it('rejects empty timings before reaching either path', () => {
|
|
224
226
|
const { calls, host } = makeHost();
|
|
225
|
-
expect(vibrateDeviceWaveform(host, [], [])).toBe(false);
|
|
227
|
+
expect(vibrateDeviceWaveform(host.input.haptics, [], [])).toBe(false);
|
|
226
228
|
expect(calls).toEqual([]);
|
|
227
229
|
});
|
|
228
230
|
});
|