chayns-api 3.6.2 → 3.6.4
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/cjs/types/IChaynsReact.js +7 -1
- package/dist/cjs/wrapper/AppWrapper.js +18 -4
- package/dist/esm/types/IChaynsReact.js +6 -0
- package/dist/esm/wrapper/AppWrapper.js +18 -4
- package/dist/types/hooks/useSafeArea.d.ts +3 -0
- package/dist/types/types/IChaynsReact.d.ts +10 -0
- package/dist/types/wrapper/AppWrapper.d.ts +2 -2
- package/package.json +2 -1
- package/tests/safe-area.test.cjs +176 -0
- package/tests/safe-area.types.ts +12 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.selectType = exports.WeekDayType = exports.ToastType = exports.TappEvent = exports.SnapshotType = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnvironment = exports.RuntimeEnviroment = exports.MediaType = exports.LoginState = exports.Language = exports.IconType = exports.IconStyle = exports.IOSFeedbackVibration = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.FloatingButtonAnimation = exports.FileExplorerSortType = exports.FileExplorerFilterType = exports.Environment = exports.DialogType = exports.DialogSelectType = exports.DialogInputType = exports.DialogIconType = exports.DialogButtonType = exports.DialogAnimation = exports.DeviceOs = exports.DesignSettingsUpdateTappViewModes = exports.DesignSettingsUpdateSeasonTypes = exports.DesignSettingsUpdateGalleryAnimationTypes = exports.DesignSettingsUpdateCoverTypes = exports.DesignSettingsUpdateBackgroundType = exports.DateType = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AppFlavor = exports.AccessMode = void 0;
|
|
6
|
+
exports.selectType = exports.WeekDayType = exports.ToastType = exports.TappEvent = exports.SnapshotType = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnvironment = exports.RuntimeEnviroment = exports.MediaType = exports.LoginState = exports.Language = exports.IconType = exports.IconStyle = exports.IOSFeedbackVibration = exports.HingeStatus = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.FloatingButtonAnimation = exports.FileExplorerSortType = exports.FileExplorerFilterType = exports.Environment = exports.DialogType = exports.DialogSelectType = exports.DialogInputType = exports.DialogIconType = exports.DialogButtonType = exports.DialogAnimation = exports.DeviceOs = exports.DesignSettingsUpdateTappViewModes = exports.DesignSettingsUpdateSeasonTypes = exports.DesignSettingsUpdateGalleryAnimationTypes = exports.DesignSettingsUpdateCoverTypes = exports.DesignSettingsUpdateBackgroundType = exports.DateType = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AppFlavor = exports.AccessMode = void 0;
|
|
7
7
|
let DateType = exports.DateType = function (DateType) {
|
|
8
8
|
DateType[DateType["DATE"] = 0] = "DATE";
|
|
9
9
|
DateType[DateType["TIME"] = 1] = "TIME";
|
|
@@ -350,4 +350,10 @@ let DialogIconType = exports.DialogIconType = function (DialogIconType) {
|
|
|
350
350
|
DialogIconType["WarningIcon"] = "%%DialogWarningIcon%%";
|
|
351
351
|
DialogIconType["ErrorIcon"] = "%%DialogErrorIcon%%";
|
|
352
352
|
return DialogIconType;
|
|
353
|
+
}({});
|
|
354
|
+
let HingeStatus = exports.HingeStatus = function (HingeStatus) {
|
|
355
|
+
HingeStatus["Closed"] = "closed";
|
|
356
|
+
HingeStatus["PartiallyOpen"] = "partiallyOpen";
|
|
357
|
+
HingeStatus["FullyOpen"] = "fullyOpen";
|
|
358
|
+
return HingeStatus;
|
|
353
359
|
}({});
|
|
@@ -45,7 +45,7 @@ class AppWrapper {
|
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
mapOldApiToNew(retVal) {
|
|
48
|
-
var _window, _window2, _AppInfo$TappSelected;
|
|
48
|
+
var _window, _window2, _AppUser$UACGroups$ma, _AppUser$UACGroups, _AppInfo$TappSelected;
|
|
49
49
|
const {
|
|
50
50
|
AppInfo,
|
|
51
51
|
AppUser,
|
|
@@ -138,7 +138,9 @@ class AppWrapper {
|
|
|
138
138
|
userId: userId,
|
|
139
139
|
personId: AppUser.PersonID,
|
|
140
140
|
isAnonymous: AppUser.IsAnonymous,
|
|
141
|
-
uacGroups:
|
|
141
|
+
uacGroups: (_AppUser$UACGroups$ma = (_AppUser$UACGroups = AppUser.UACGroups) === null || _AppUser$UACGroups === void 0 ? void 0 : _AppUser$UACGroups.map(group => ({
|
|
142
|
+
id: group.GroupID
|
|
143
|
+
}))) !== null && _AppUser$UACGroups$ma !== void 0 ? _AppUser$UACGroups$ma : []
|
|
142
144
|
},
|
|
143
145
|
customData: null,
|
|
144
146
|
isAdminModeActive: AppUser.AdminMode,
|
|
@@ -306,7 +308,13 @@ class AppWrapper {
|
|
|
306
308
|
top: v.top,
|
|
307
309
|
left: v.left,
|
|
308
310
|
bottom: v.bottom,
|
|
309
|
-
right: v.right
|
|
311
|
+
right: v.right,
|
|
312
|
+
...(v.hingeAngle === undefined ? {} : {
|
|
313
|
+
hingeAngle: v.hingeAngle
|
|
314
|
+
}),
|
|
315
|
+
...(v.hingeStatus === undefined ? {} : {
|
|
316
|
+
hingeStatus: v.hingeStatus
|
|
317
|
+
})
|
|
310
318
|
};
|
|
311
319
|
(0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', this.latestAppleSafeArea);
|
|
312
320
|
}
|
|
@@ -367,7 +375,13 @@ class AppWrapper {
|
|
|
367
375
|
top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
|
|
368
376
|
left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
|
|
369
377
|
bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
|
|
370
|
-
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0
|
|
378
|
+
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0,
|
|
379
|
+
...((v === null || v === void 0 ? void 0 : v.hingeAngle) === undefined ? {} : {
|
|
380
|
+
hingeAngle: v.hingeAngle
|
|
381
|
+
}),
|
|
382
|
+
...((v === null || v === void 0 ? void 0 : v.hingeStatus) === undefined ? {} : {
|
|
383
|
+
hingeStatus: v.hingeStatus
|
|
384
|
+
})
|
|
371
385
|
};
|
|
372
386
|
return this.latestAppleSafeArea;
|
|
373
387
|
},
|
|
@@ -344,4 +344,10 @@ export let DialogIconType = function (DialogIconType) {
|
|
|
344
344
|
DialogIconType["WarningIcon"] = "%%DialogWarningIcon%%";
|
|
345
345
|
DialogIconType["ErrorIcon"] = "%%DialogErrorIcon%%";
|
|
346
346
|
return DialogIconType;
|
|
347
|
+
}({});
|
|
348
|
+
export let HingeStatus = function (HingeStatus) {
|
|
349
|
+
HingeStatus["Closed"] = "closed";
|
|
350
|
+
HingeStatus["PartiallyOpen"] = "partiallyOpen";
|
|
351
|
+
HingeStatus["FullyOpen"] = "fullyOpen";
|
|
352
|
+
return HingeStatus;
|
|
347
353
|
}({});
|
|
@@ -32,7 +32,7 @@ export class AppWrapper {
|
|
|
32
32
|
return undefined;
|
|
33
33
|
}
|
|
34
34
|
mapOldApiToNew(retVal) {
|
|
35
|
-
var _window, _window2, _AppInfo$TappSelected;
|
|
35
|
+
var _window, _window2, _AppUser$UACGroups$ma, _AppUser$UACGroups, _AppInfo$TappSelected;
|
|
36
36
|
const {
|
|
37
37
|
AppInfo,
|
|
38
38
|
AppUser,
|
|
@@ -125,7 +125,9 @@ export class AppWrapper {
|
|
|
125
125
|
userId: userId,
|
|
126
126
|
personId: AppUser.PersonID,
|
|
127
127
|
isAnonymous: AppUser.IsAnonymous,
|
|
128
|
-
uacGroups:
|
|
128
|
+
uacGroups: (_AppUser$UACGroups$ma = (_AppUser$UACGroups = AppUser.UACGroups) === null || _AppUser$UACGroups === void 0 ? void 0 : _AppUser$UACGroups.map(group => ({
|
|
129
|
+
id: group.GroupID
|
|
130
|
+
}))) !== null && _AppUser$UACGroups$ma !== void 0 ? _AppUser$UACGroups$ma : []
|
|
129
131
|
},
|
|
130
132
|
customData: null,
|
|
131
133
|
isAdminModeActive: AppUser.AdminMode,
|
|
@@ -269,7 +271,13 @@ export class AppWrapper {
|
|
|
269
271
|
top: v.top,
|
|
270
272
|
left: v.left,
|
|
271
273
|
bottom: v.bottom,
|
|
272
|
-
right: v.right
|
|
274
|
+
right: v.right,
|
|
275
|
+
...(v.hingeAngle === undefined ? {} : {
|
|
276
|
+
hingeAngle: v.hingeAngle
|
|
277
|
+
}),
|
|
278
|
+
...(v.hingeStatus === undefined ? {} : {
|
|
279
|
+
hingeStatus: v.hingeStatus
|
|
280
|
+
})
|
|
273
281
|
};
|
|
274
282
|
dispatchApiEvent('appleSafeAreaListener', this.latestAppleSafeArea);
|
|
275
283
|
}
|
|
@@ -330,7 +338,13 @@ export class AppWrapper {
|
|
|
330
338
|
top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
|
|
331
339
|
left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
|
|
332
340
|
bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
|
|
333
|
-
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0
|
|
341
|
+
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0,
|
|
342
|
+
...((v === null || v === void 0 ? void 0 : v.hingeAngle) === undefined ? {} : {
|
|
343
|
+
hingeAngle: v.hingeAngle
|
|
344
|
+
}),
|
|
345
|
+
...((v === null || v === void 0 ? void 0 : v.hingeStatus) === undefined ? {} : {
|
|
346
|
+
hingeStatus: v.hingeStatus
|
|
347
|
+
})
|
|
334
348
|
};
|
|
335
349
|
return this.latestAppleSafeArea;
|
|
336
350
|
},
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { AppleSafeArea } from '../types/IChaynsReact';
|
|
2
2
|
/**
|
|
3
|
+
* Listens for safe-area and optional iPhone Duo hinge updates from the native app.
|
|
3
4
|
* @category Hooks
|
|
4
5
|
*/
|
|
5
6
|
export declare const useSafeAreaListener: () => (callback: (result: AppleSafeArea) => void) => () => void;
|
|
6
7
|
/**
|
|
8
|
+
* Returns safe-area insets and optional iPhone Duo hinge metadata.
|
|
9
|
+
* Hinge updates allow layouts to react when the device is opened or closed.
|
|
7
10
|
* @category Hooks
|
|
8
11
|
*/
|
|
9
12
|
export declare const useSafeArea: ({ enabled }?: {
|
|
@@ -1118,11 +1118,21 @@ export declare enum DialogIconType {
|
|
|
1118
1118
|
export type AnonymousAccountResult = {
|
|
1119
1119
|
token: string;
|
|
1120
1120
|
};
|
|
1121
|
+
/** Hinge posture reported by the native app on iPhone Duo. */
|
|
1122
|
+
export declare enum HingeStatus {
|
|
1123
|
+
Closed = "closed",
|
|
1124
|
+
PartiallyOpen = "partiallyOpen",
|
|
1125
|
+
FullyOpen = "fullyOpen"
|
|
1126
|
+
}
|
|
1121
1127
|
export interface AppleSafeArea {
|
|
1122
1128
|
top: number;
|
|
1123
1129
|
left: number;
|
|
1124
1130
|
bottom: number;
|
|
1125
1131
|
right: number;
|
|
1132
|
+
/** Only provided by the native app on iPhone Duo. */
|
|
1133
|
+
hingeAngle?: number;
|
|
1134
|
+
/** Only provided by the native app on iPhone Duo. */
|
|
1135
|
+
hingeStatus?: HingeStatus;
|
|
1126
1136
|
}
|
|
1127
1137
|
export type PageMainGroupType = {
|
|
1128
1138
|
Id: 1;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ChaynsReactFunctions, ChaynsReactValues, ChaynsStyleSettings, CleanupCallback, DataChangeCallback, IChaynsReact } from '../types/IChaynsReact';
|
|
1
|
+
import { AppleSafeArea, ChaynsReactFunctions, ChaynsReactValues, ChaynsStyleSettings, CleanupCallback, DataChangeCallback, IChaynsReact } from '../types/IChaynsReact';
|
|
2
2
|
export declare class AppWrapper implements IChaynsReact {
|
|
3
3
|
values: ChaynsReactValues;
|
|
4
4
|
history: IChaynsReact['history'];
|
|
5
5
|
accessToken: string;
|
|
6
|
-
latestAppleSafeArea: null;
|
|
6
|
+
latestAppleSafeArea: AppleSafeArea | null;
|
|
7
7
|
private trustedDomains;
|
|
8
8
|
listeners: (() => void)[];
|
|
9
9
|
customFunctions: {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chayns-api",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.4",
|
|
4
4
|
"description": "new chayns api",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dev": "npm link && npm run watch",
|
|
37
37
|
"format": "prettier . --write",
|
|
38
38
|
"lint": "eslint src",
|
|
39
|
+
"test:safe-area": "npm run build:cjs && npm run build:typescript && node --test tests/safe-area.test.cjs && tsc --noEmit --strict --target ES2020 --module commonjs --esModuleInterop --skipLibCheck tests/safe-area.types.ts",
|
|
39
40
|
"prepublishOnly": "npm run build:cjs && npm run build:esm && npm run build:typescript",
|
|
40
41
|
"preversion": "npm run build:typescript -- --noEmit"
|
|
41
42
|
},
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const { afterEach, beforeEach, test } = require('node:test');
|
|
3
|
+
const { JSDOM } = require('jsdom');
|
|
4
|
+
|
|
5
|
+
const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'https://example.test' });
|
|
6
|
+
global.window = dom.window;
|
|
7
|
+
global.document = dom.window.document;
|
|
8
|
+
Object.defineProperty(global, 'navigator', { configurable: true, value: dom.window.navigator });
|
|
9
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
10
|
+
|
|
11
|
+
const { act, createElement, StrictMode } = require('react');
|
|
12
|
+
const { createRoot } = require('react-dom/client');
|
|
13
|
+
const { ChaynsContext } = require('../dist/cjs/components/ChaynsContext');
|
|
14
|
+
const { useSafeArea } = require('../dist/cjs/hooks/useSafeArea');
|
|
15
|
+
const { AppName, HingeStatus } = require('../dist/cjs/types/IChaynsReact');
|
|
16
|
+
const { AppWrapper } = require('../dist/cjs/wrapper/AppWrapper');
|
|
17
|
+
const { normalizeFunctions } = require('../dist/cjs/wrapper/normalizeFunctions');
|
|
18
|
+
|
|
19
|
+
const insets = { top: 12, left: 17, bottom: 20, right: 43 };
|
|
20
|
+
let wrapper;
|
|
21
|
+
let nativeCalls;
|
|
22
|
+
let listenerIds;
|
|
23
|
+
let root;
|
|
24
|
+
let currentValue;
|
|
25
|
+
|
|
26
|
+
const emit = (value, call = nativeCalls.at(-1)) => {
|
|
27
|
+
const callbackName = call.value.callback.replace(/^window\./, '');
|
|
28
|
+
window[callbackName]({ retVal: value });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const subscribe = async (callback) => {
|
|
32
|
+
const id = await wrapper.functions.addAppleSafeAreaListener(callback);
|
|
33
|
+
listenerIds.push(id);
|
|
34
|
+
return id;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const Probe = ({ enabled }) => {
|
|
38
|
+
currentValue = useSafeArea({ enabled });
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const renderHook = async (enabled = true) => {
|
|
43
|
+
root ??= createRoot(document.createElement('div'));
|
|
44
|
+
await act(async () => {
|
|
45
|
+
root.render(createElement(StrictMode, null, createElement(ChaynsContext.Provider, { value: wrapper }, createElement(Probe, { enabled }))));
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
wrapper = new AppWrapper();
|
|
51
|
+
wrapper.values = { device: { os: 'iOS', app: { name: AppName.Sidekick, appVersion: 2120 } } };
|
|
52
|
+
nativeCalls = [];
|
|
53
|
+
listenerIds = [];
|
|
54
|
+
root = undefined;
|
|
55
|
+
currentValue = undefined;
|
|
56
|
+
window.webkit = { messageHandlers: { jsonCall: { postMessage: (json) => nativeCalls.push(JSON.parse(json)) } } };
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(async () => {
|
|
60
|
+
if (root) await act(async () => root.unmount());
|
|
61
|
+
for (const id of listenerIds) await wrapper.functions.removeAppleSafeAreaListener(id);
|
|
62
|
+
for (const key of Object.keys(window)) {
|
|
63
|
+
if (key.startsWith('chaynsApiV5Callback_')) delete window[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('exports the three native hinge status values through the public entry point', () => {
|
|
68
|
+
assert.deepEqual(HingeStatus, { Closed: 'closed', PartiallyOpen: 'partiallyOpen', FullyOpen: 'fullyOpen' });
|
|
69
|
+
assert.equal(require('../dist/cjs').HingeStatus, HingeStatus);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
for (const hingeStatus of Object.values(HingeStatus)) {
|
|
73
|
+
test(`preserves ${hingeStatus} and a zero angle in a direct safe-area request`, async () => {
|
|
74
|
+
const expected = { ...insets, hingeAngle: 0, hingeStatus };
|
|
75
|
+
const pending = wrapper.functions.getAppleSafeArea();
|
|
76
|
+
assert.equal(nativeCalls[0].action, 300);
|
|
77
|
+
emit({ ...expected, unrelated: 'ignored' });
|
|
78
|
+
assert.deepEqual(await pending, expected);
|
|
79
|
+
assert.deepEqual(await wrapper.functions.getAppleSafeArea(), expected);
|
|
80
|
+
assert.equal(nativeCalls.length, 1);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
test('keeps ordinary iPhones free of hinge properties in requests and listener updates', async () => {
|
|
85
|
+
const pending = wrapper.functions.getAppleSafeArea();
|
|
86
|
+
emit(insets);
|
|
87
|
+
assert.deepEqual(await pending, insets);
|
|
88
|
+
const values = [];
|
|
89
|
+
await subscribe((value) => values.push(value));
|
|
90
|
+
emit(insets);
|
|
91
|
+
assert.deepEqual(values, [insets, insets]);
|
|
92
|
+
assert.equal(Object.hasOwn(values[1], 'hingeAngle'), false);
|
|
93
|
+
assert.equal(Object.hasOwn(values[1], 'hingeStatus'), false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('retains the existing zero-inset fallback for an absent native response', async () => {
|
|
97
|
+
const pending = wrapper.functions.getAppleSafeArea();
|
|
98
|
+
emit(undefined);
|
|
99
|
+
assert.deepEqual(await pending, { top: 0, left: 0, bottom: 0, right: 0 });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('updates the listener cache and new subscribers when only hinge metadata changes', async () => {
|
|
103
|
+
const values = [];
|
|
104
|
+
await subscribe((value) => values.push(value));
|
|
105
|
+
const stream = nativeCalls[0];
|
|
106
|
+
for (const hingeStatus of Object.values(HingeStatus)) {
|
|
107
|
+
const expected = { ...insets, hingeAngle: 90, hingeStatus };
|
|
108
|
+
emit(expected, stream);
|
|
109
|
+
assert.deepEqual(values.at(-1), expected);
|
|
110
|
+
assert.deepEqual(await wrapper.functions.getAppleSafeArea(), expected);
|
|
111
|
+
}
|
|
112
|
+
const replay = [];
|
|
113
|
+
await subscribe((value) => replay.push(value));
|
|
114
|
+
assert.deepEqual(replay, [values.at(-1)]);
|
|
115
|
+
assert.equal(nativeCalls.length, 1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('stops delivering native updates to removed listeners', async () => {
|
|
119
|
+
const values = [];
|
|
120
|
+
const id = await subscribe((value) => values.push(value));
|
|
121
|
+
await wrapper.functions.removeAppleSafeAreaListener(id);
|
|
122
|
+
listenerIds = [];
|
|
123
|
+
emit({ ...insets, hingeAngle: 90, hingeStatus: HingeStatus.PartiallyOpen });
|
|
124
|
+
assert.deepEqual(values, []);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('passes hinge updates through the existing compatibility fallback unchanged', async () => {
|
|
128
|
+
let dispatch;
|
|
129
|
+
const functions = normalizeFunctions({
|
|
130
|
+
invokeCall: (options, callback) => {
|
|
131
|
+
assert.equal(options.action, 300);
|
|
132
|
+
dispatch = callback;
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const values = [];
|
|
137
|
+
const id = await functions.addAppleSafeAreaListener((value) => values.push(value));
|
|
138
|
+
const expected = { ...insets, hingeAngle: 90, hingeStatus: HingeStatus.PartiallyOpen };
|
|
139
|
+
dispatch(expected);
|
|
140
|
+
assert.deepEqual(values, [expected]);
|
|
141
|
+
assert.deepEqual(await functions.getAppleSafeArea(), expected);
|
|
142
|
+
await functions.removeAppleSafeAreaListener(id);
|
|
143
|
+
dispatch({ ...expected, hingeStatus: HingeStatus.FullyOpen });
|
|
144
|
+
assert.deepEqual(values, [expected]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('updates the actual hook through native folding events with identical insets', async () => {
|
|
148
|
+
await renderHook();
|
|
149
|
+
const stream = nativeCalls[0];
|
|
150
|
+
for (const hingeStatus of Object.values(HingeStatus)) {
|
|
151
|
+
const expected = { ...insets, hingeAngle: 90, hingeStatus };
|
|
152
|
+
await act(async () => emit(expected, stream));
|
|
153
|
+
assert.deepEqual(currentValue, expected);
|
|
154
|
+
}
|
|
155
|
+
assert.equal(nativeCalls.length, 1);
|
|
156
|
+
const beforeCleanup = currentValue;
|
|
157
|
+
await renderHook(false);
|
|
158
|
+
emit({ ...insets, hingeAngle: 0, hingeStatus: HingeStatus.Closed }, stream);
|
|
159
|
+
assert.equal(currentValue, beforeCleanup);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('returns only insets on ordinary devices and retains disabled-hook behavior', async () => {
|
|
163
|
+
await renderHook(false);
|
|
164
|
+
assert.deepEqual(currentValue, { top: 0, left: 0, bottom: 0, right: 0 });
|
|
165
|
+
assert.equal(nativeCalls.length, 0);
|
|
166
|
+
await renderHook();
|
|
167
|
+
await act(async () => emit(insets));
|
|
168
|
+
assert.deepEqual(currentValue, insets);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('does not register native listeners on unsupported runtimes', async () => {
|
|
172
|
+
wrapper.values.device.os = 'Android';
|
|
173
|
+
await renderHook();
|
|
174
|
+
assert.equal(nativeCalls.length, 0);
|
|
175
|
+
assert.deepEqual(currentValue, { top: 0, left: 0, bottom: 0, right: 0 });
|
|
176
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { addAppleSafeAreaListener, AppleSafeArea, getSafeArea, HingeStatus, useSafeArea, useSafeAreaListener } from '../dist/types';
|
|
2
|
+
|
|
3
|
+
const ordinaryPhone: AppleSafeArea = { top: 12, left: 17, bottom: 20, right: 43 };
|
|
4
|
+
const duo: AppleSafeArea = { ...ordinaryPhone, hingeAngle: 0, hingeStatus: HingeStatus.Closed };
|
|
5
|
+
|
|
6
|
+
declare const hookValue: ReturnType<typeof useSafeArea>;
|
|
7
|
+
const hingeAngle: number | undefined = hookValue.hingeAngle;
|
|
8
|
+
const hingeStatus: HingeStatus | undefined = hookValue.hingeStatus;
|
|
9
|
+
|
|
10
|
+
const getInsets: () => Promise<AppleSafeArea> = getSafeArea;
|
|
11
|
+
const addListener: (callback: (value: AppleSafeArea) => void) => Promise<number> = addAppleSafeAreaListener;
|
|
12
|
+
const useListener: () => (callback: (value: AppleSafeArea) => void) => () => void = useSafeAreaListener;
|