chayns-api 3.6.5 → 3.6.7
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/calls/appleSafeAreaListener.js +13 -4
- package/dist/cjs/hooks/useSafeArea.js +11 -25
- package/dist/cjs/wrapper/AppWrapper.js +51 -13
- package/dist/cjs/wrapper/normalizeFunctions.js +61 -32
- package/dist/esm/calls/appleSafeAreaListener.js +12 -3
- package/dist/esm/hooks/useSafeArea.js +12 -26
- package/dist/esm/wrapper/AppWrapper.js +51 -13
- package/dist/esm/wrapper/normalizeFunctions.js +61 -32
- package/dist/types/calls/appleSafeAreaListener.d.ts +5 -5
- package/dist/types/wrapper/AppWrapper.d.ts +3 -1
- package/package.json +1 -1
- package/tests/safe-area.test.cjs +71 -320
- package/dist/cjs/utils/appleSafeArea.js +0 -101
- package/dist/esm/utils/appleSafeArea.js +0 -92
- package/dist/types/utils/appleSafeArea.d.ts +0 -9
|
@@ -4,12 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.addAppleSafeAreaListener = void 0;
|
|
7
|
-
var _index = require("./index");
|
|
8
7
|
const addAppleSafeAreaListener = ({
|
|
9
|
-
callback
|
|
8
|
+
callback,
|
|
9
|
+
invokeCall
|
|
10
10
|
}) => {
|
|
11
|
-
void
|
|
11
|
+
void invokeCall({
|
|
12
12
|
action: 300
|
|
13
|
-
},
|
|
13
|
+
}, result => {
|
|
14
|
+
const value = result && 'retVal' in result ? result.retVal : result;
|
|
15
|
+
callback({
|
|
16
|
+
top: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
right: 0,
|
|
20
|
+
...value
|
|
21
|
+
});
|
|
22
|
+
});
|
|
14
23
|
};
|
|
15
24
|
exports.addAppleSafeAreaListener = addAppleSafeAreaListener;
|
|
@@ -30,24 +30,16 @@ const isSafeAreaSupported = (os, app) => {
|
|
|
30
30
|
return app.appVersion >= minVersion;
|
|
31
31
|
};
|
|
32
32
|
const useSafeAreaListener = () => {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
listenerId.then(removeListener);
|
|
42
|
-
};
|
|
33
|
+
const addListener = (0, _context.useFunctionsSelector)(f => f.addAppleSafeAreaListener);
|
|
34
|
+
const removeListener = (0, _context.useFunctionsSelector)(f => f.removeAppleSafeAreaListener);
|
|
35
|
+
const promiseRef = (0, _react.useRef)();
|
|
36
|
+
return (0, _react.useCallback)(callback => {
|
|
37
|
+
promiseRef.current = addListener(callback);
|
|
38
|
+
return () => {
|
|
39
|
+
var _promiseRef$current;
|
|
40
|
+
void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
|
|
43
41
|
};
|
|
44
|
-
|
|
45
|
-
$[1] = removeListener;
|
|
46
|
-
$[2] = t0;
|
|
47
|
-
} else {
|
|
48
|
-
t0 = $[2];
|
|
49
|
-
}
|
|
50
|
-
return t0;
|
|
42
|
+
}, []);
|
|
51
43
|
};
|
|
52
44
|
exports.useSafeAreaListener = useSafeAreaListener;
|
|
53
45
|
const useSafeArea = t0 => {
|
|
@@ -78,7 +70,7 @@ const useSafeArea = t0 => {
|
|
|
78
70
|
}
|
|
79
71
|
const [value, setValue] = (0, _react.useState)(t3);
|
|
80
72
|
const addListener = useSafeAreaListener();
|
|
81
|
-
const device = (0, _context.useValuesSelector)(
|
|
73
|
+
const device = (0, _context.useValuesSelector)(_temp);
|
|
82
74
|
let t4;
|
|
83
75
|
if ($[3] !== device.app || $[4] !== device.os) {
|
|
84
76
|
t4 = isSafeAreaSupported(device.os, device.app);
|
|
@@ -113,12 +105,6 @@ const useSafeArea = t0 => {
|
|
|
113
105
|
return value;
|
|
114
106
|
};
|
|
115
107
|
exports.useSafeArea = useSafeArea;
|
|
116
|
-
function _temp(
|
|
117
|
-
return f.addAppleSafeAreaListener;
|
|
118
|
-
}
|
|
119
|
-
function _temp2(f_0) {
|
|
120
|
-
return f_0.removeAppleSafeAreaListener;
|
|
121
|
-
}
|
|
122
|
-
function _temp3(v) {
|
|
108
|
+
function _temp(v) {
|
|
123
109
|
return v.device;
|
|
124
110
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.AppWrapper = void 0;
|
|
7
7
|
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
8
8
|
var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
|
|
9
|
+
var _appleSafeAreaListener = require("../calls/appleSafeAreaListener");
|
|
9
10
|
var _sendMessage = require("../calls/sendMessage");
|
|
10
11
|
var _constants = require("../constants");
|
|
11
12
|
var _trustedDomains = require("../constants/trustedDomains");
|
|
@@ -15,7 +16,6 @@ var _DialogHandler = _interopRequireDefault(require("../handler/DialogHandler"))
|
|
|
15
16
|
var _apiListener = require("../utils/apiListener");
|
|
16
17
|
var _IChaynsReact = require("../types/IChaynsReact");
|
|
17
18
|
var _appCall = _interopRequireDefault(require("../utils/appCall"));
|
|
18
|
-
var _appleSafeArea = require("../utils/appleSafeArea");
|
|
19
19
|
var _appStorage = require("../utils/appStorage");
|
|
20
20
|
var _deviceHelper = _interopRequireWildcard(require("../utils/deviceHelper"));
|
|
21
21
|
var _is = require("../utils/is");
|
|
@@ -25,6 +25,7 @@ class AppWrapper {
|
|
|
25
25
|
values = null;
|
|
26
26
|
history = null;
|
|
27
27
|
accessToken = '';
|
|
28
|
+
latestAppleSafeArea = null;
|
|
28
29
|
trustedDomains = _trustedDomains.DefaultTrustedDomains;
|
|
29
30
|
listeners = [];
|
|
30
31
|
customFunctions = {};
|
|
@@ -166,6 +167,13 @@ class AppWrapper {
|
|
|
166
167
|
console.warn(`call ${call} not implement in app`);
|
|
167
168
|
}
|
|
168
169
|
counter = 0;
|
|
170
|
+
getCallbackName() {
|
|
171
|
+
let callbackName;
|
|
172
|
+
do {
|
|
173
|
+
callbackName = `chaynsApiV5Callback_${this.counter++}`;
|
|
174
|
+
} while (callbackName in window);
|
|
175
|
+
return callbackName;
|
|
176
|
+
}
|
|
169
177
|
appCall(action, value = {}, {
|
|
170
178
|
callback,
|
|
171
179
|
awaitResult = true
|
|
@@ -178,7 +186,7 @@ class AppWrapper {
|
|
|
178
186
|
return;
|
|
179
187
|
}
|
|
180
188
|
return new Promise(resolve => {
|
|
181
|
-
const callbackName =
|
|
189
|
+
const callbackName = this.getCallbackName();
|
|
182
190
|
window[callbackName] = v => {
|
|
183
191
|
var _v$retVal2;
|
|
184
192
|
if (callback) {
|
|
@@ -293,7 +301,28 @@ class AppWrapper {
|
|
|
293
301
|
}
|
|
294
302
|
return id;
|
|
295
303
|
},
|
|
296
|
-
addAppleSafeAreaListener: callback =>
|
|
304
|
+
addAppleSafeAreaListener: async callback => {
|
|
305
|
+
const {
|
|
306
|
+
id,
|
|
307
|
+
shouldInitialize
|
|
308
|
+
} = (0, _apiListener.addApiListener)('appleSafeAreaListener', value => {
|
|
309
|
+
this.latestAppleSafeArea = value;
|
|
310
|
+
callback(value);
|
|
311
|
+
});
|
|
312
|
+
if (this.latestAppleSafeArea) {
|
|
313
|
+
callback(this.latestAppleSafeArea);
|
|
314
|
+
}
|
|
315
|
+
if (shouldInitialize) {
|
|
316
|
+
(0, _appleSafeAreaListener.addAppleSafeAreaListener)({
|
|
317
|
+
invokeCall: this.functions.invokeCall,
|
|
318
|
+
callback: value => {
|
|
319
|
+
this.latestAppleSafeArea = value;
|
|
320
|
+
(0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', value);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return id;
|
|
325
|
+
},
|
|
297
326
|
customCallbackFunction: async () => {
|
|
298
327
|
this.notImplemented('customCallbackFunction');
|
|
299
328
|
},
|
|
@@ -337,15 +366,22 @@ class AppWrapper {
|
|
|
337
366
|
pageWidth: window.innerWidth,
|
|
338
367
|
topBarHeight: 0
|
|
339
368
|
}),
|
|
340
|
-
getAppleSafeArea: () =>
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
369
|
+
getAppleSafeArea: async () => {
|
|
370
|
+
if (this.latestAppleSafeArea) {
|
|
371
|
+
return this.latestAppleSafeArea;
|
|
372
|
+
}
|
|
373
|
+
let resolveValue;
|
|
374
|
+
const result = new Promise(resolve => {
|
|
375
|
+
resolveValue = resolve;
|
|
376
|
+
});
|
|
377
|
+
const id = await this.functions.addAppleSafeAreaListener(resolveValue);
|
|
378
|
+
try {
|
|
379
|
+
return await result;
|
|
380
|
+
} finally {
|
|
381
|
+
await this.functions.removeAppleSafeAreaListener(id);
|
|
348
382
|
}
|
|
383
|
+
},
|
|
384
|
+
invokeCall: async (value, callback) => {
|
|
349
385
|
return this.appCall(value.action, value.value, {
|
|
350
386
|
callback
|
|
351
387
|
});
|
|
@@ -356,7 +392,7 @@ class AppWrapper {
|
|
|
356
392
|
});
|
|
357
393
|
},
|
|
358
394
|
invokeDialogCall: async (value, callback) => {
|
|
359
|
-
const callbackName =
|
|
395
|
+
const callbackName = this.getCallbackName();
|
|
360
396
|
window[callbackName] = ({
|
|
361
397
|
retVal
|
|
362
398
|
}) => {
|
|
@@ -485,7 +521,9 @@ class AppWrapper {
|
|
|
485
521
|
this.resizeListener = null;
|
|
486
522
|
}
|
|
487
523
|
},
|
|
488
|
-
removeAppleSafeAreaListener: id =>
|
|
524
|
+
removeAppleSafeAreaListener: async id => {
|
|
525
|
+
(0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
|
|
526
|
+
},
|
|
489
527
|
selectPage: async options => {
|
|
490
528
|
var _this$values, _this$values2;
|
|
491
529
|
if ((_this$values = this.values) !== null && _this$values !== void 0 && (_this$values = _this$values.site) !== null && _this$values !== void 0 && _this$values.id && options.siteId && options.siteId !== ((_this$values2 = this.values) === null || _this$values2 === void 0 || (_this$values2 = _this$values2.site) === null || _this$values2 === void 0 ? void 0 : _this$values2.id)) {
|
|
@@ -4,31 +4,73 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.normalizeFunctions = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _appleSafeAreaListener = require("../calls/appleSafeAreaListener");
|
|
8
|
+
var _apiListener = require("../utils/apiListener");
|
|
8
9
|
const createAppleSafeAreaFunctions = functions => {
|
|
9
|
-
var _ref, _runtimeFunctions$add;
|
|
10
10
|
const runtimeFunctions = functions;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let latestValue = null;
|
|
12
|
+
const addAppleSafeAreaListener = callback => {
|
|
13
|
+
const handleValue = value => {
|
|
14
|
+
latestValue = value;
|
|
15
|
+
callback(value);
|
|
16
|
+
};
|
|
13
17
|
if (runtimeFunctions.addAppleSafeAreaListener) {
|
|
14
|
-
return runtimeFunctions.addAppleSafeAreaListener(
|
|
18
|
+
return runtimeFunctions.addAppleSafeAreaListener(handleValue);
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const {
|
|
21
|
+
id,
|
|
22
|
+
shouldInitialize
|
|
23
|
+
} = (0, _apiListener.addApiListener)('appleSafeAreaListener', handleValue);
|
|
24
|
+
if (latestValue) {
|
|
25
|
+
callback(latestValue);
|
|
20
26
|
}
|
|
21
|
-
if (runtimeFunctions.
|
|
22
|
-
|
|
27
|
+
if (shouldInitialize && runtimeFunctions.invokeCall) {
|
|
28
|
+
(0, _appleSafeAreaListener.addAppleSafeAreaListener)({
|
|
29
|
+
invokeCall: runtimeFunctions.invokeCall,
|
|
30
|
+
callback: value => {
|
|
31
|
+
latestValue = value;
|
|
32
|
+
(0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', value);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return Promise.resolve(id);
|
|
37
|
+
};
|
|
38
|
+
const removeAppleSafeAreaListener = id => {
|
|
39
|
+
if (runtimeFunctions.addAppleSafeAreaListener) {
|
|
40
|
+
var _runtimeFunctions$rem, _runtimeFunctions$rem2;
|
|
41
|
+
return (_runtimeFunctions$rem = (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) === null || _runtimeFunctions$rem2 === void 0 ? void 0 : _runtimeFunctions$rem2.call(runtimeFunctions, id)) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
(0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
};
|
|
46
|
+
const getAppleSafeArea = async () => {
|
|
47
|
+
if (latestValue) {
|
|
48
|
+
return latestValue;
|
|
49
|
+
}
|
|
50
|
+
if (!runtimeFunctions.addAppleSafeAreaListener && !runtimeFunctions.invokeCall) {
|
|
51
|
+
return {
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
bottom: 0,
|
|
55
|
+
right: 0
|
|
56
|
+
};
|
|
23
57
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
bottom: 0,
|
|
28
|
-
right: 0
|
|
58
|
+
let resolveValue;
|
|
59
|
+
const result = new Promise(resolve => {
|
|
60
|
+
resolveValue = resolve;
|
|
29
61
|
});
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
const id = await addAppleSafeAreaListener(resolveValue);
|
|
63
|
+
try {
|
|
64
|
+
return await result;
|
|
65
|
+
} finally {
|
|
66
|
+
await removeAppleSafeAreaListener(id);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
addAppleSafeAreaListener,
|
|
71
|
+
removeAppleSafeAreaListener,
|
|
72
|
+
getAppleSafeArea
|
|
73
|
+
};
|
|
32
74
|
};
|
|
33
75
|
const normalizeFunctions = functions => {
|
|
34
76
|
var _runtimeFunctions$isT;
|
|
@@ -41,20 +83,7 @@ const normalizeFunctions = functions => {
|
|
|
41
83
|
...functions
|
|
42
84
|
};
|
|
43
85
|
if (!hasSafeAreaFunctions) {
|
|
44
|
-
|
|
45
|
-
Object.assign(normalizedFunctions, safeAreaFunctions);
|
|
46
|
-
if (runtimeFunctions.invokeCall) {
|
|
47
|
-
const invokeCall = runtimeFunctions.invokeCall;
|
|
48
|
-
normalizedFunctions.invokeCall = async (value, callback) => {
|
|
49
|
-
if (value.action === 300) {
|
|
50
|
-
if (callback) {
|
|
51
|
-
await safeAreaFunctions.addAppleSafeAreaListener(callback);
|
|
52
|
-
}
|
|
53
|
-
return safeAreaFunctions.getAppleSafeArea();
|
|
54
|
-
}
|
|
55
|
-
return invokeCall(value, callback);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
86
|
+
Object.assign(normalizedFunctions, createAppleSafeAreaFunctions(functions));
|
|
58
87
|
}
|
|
59
88
|
normalizedFunctions.isTrustedUrl = (_runtimeFunctions$isT = runtimeFunctions.isTrustedUrl) !== null && _runtimeFunctions$isT !== void 0 ? _runtimeFunctions$isT : () => Promise.resolve(true);
|
|
60
89
|
return normalizedFunctions;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { invokeCall } from './index';
|
|
2
1
|
export const addAppleSafeAreaListener = ({
|
|
3
|
-
callback
|
|
2
|
+
callback,
|
|
3
|
+
invokeCall
|
|
4
4
|
}) => {
|
|
5
5
|
void invokeCall({
|
|
6
6
|
action: 300
|
|
7
|
-
},
|
|
7
|
+
}, result => {
|
|
8
|
+
const value = result && 'retVal' in result ? result.retVal : result;
|
|
9
|
+
callback({
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
right: 0,
|
|
14
|
+
...value
|
|
15
|
+
});
|
|
16
|
+
});
|
|
8
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as _c } from "react-compiler-runtime";
|
|
2
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { AppName } from '../types/IChaynsReact';
|
|
4
4
|
import { useFunctionsSelector, useValuesSelector } from './context';
|
|
5
5
|
const SAFE_AREA_SUPPORT_CONFIG = {
|
|
@@ -24,24 +24,16 @@ const isSafeAreaSupported = (os, app) => {
|
|
|
24
24
|
return app.appVersion >= minVersion;
|
|
25
25
|
};
|
|
26
26
|
export const useSafeAreaListener = () => {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
listenerId.then(removeListener);
|
|
36
|
-
};
|
|
27
|
+
const addListener = useFunctionsSelector(f => f.addAppleSafeAreaListener);
|
|
28
|
+
const removeListener = useFunctionsSelector(f => f.removeAppleSafeAreaListener);
|
|
29
|
+
const promiseRef = useRef();
|
|
30
|
+
return useCallback(callback => {
|
|
31
|
+
promiseRef.current = addListener(callback);
|
|
32
|
+
return () => {
|
|
33
|
+
var _promiseRef$current;
|
|
34
|
+
void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
|
|
37
35
|
};
|
|
38
|
-
|
|
39
|
-
$[1] = removeListener;
|
|
40
|
-
$[2] = t0;
|
|
41
|
-
} else {
|
|
42
|
-
t0 = $[2];
|
|
43
|
-
}
|
|
44
|
-
return t0;
|
|
36
|
+
}, []);
|
|
45
37
|
};
|
|
46
38
|
export const useSafeArea = t0 => {
|
|
47
39
|
const $ = _c(11);
|
|
@@ -71,7 +63,7 @@ export const useSafeArea = t0 => {
|
|
|
71
63
|
}
|
|
72
64
|
const [value, setValue] = useState(t3);
|
|
73
65
|
const addListener = useSafeAreaListener();
|
|
74
|
-
const device = useValuesSelector(
|
|
66
|
+
const device = useValuesSelector(_temp);
|
|
75
67
|
let t4;
|
|
76
68
|
if ($[3] !== device.app || $[4] !== device.os) {
|
|
77
69
|
t4 = isSafeAreaSupported(device.os, device.app);
|
|
@@ -105,12 +97,6 @@ export const useSafeArea = t0 => {
|
|
|
105
97
|
useEffect(t5, t6);
|
|
106
98
|
return value;
|
|
107
99
|
};
|
|
108
|
-
function _temp(
|
|
109
|
-
return f.addAppleSafeAreaListener;
|
|
110
|
-
}
|
|
111
|
-
function _temp2(f_0) {
|
|
112
|
-
return f_0.removeAppleSafeAreaListener;
|
|
113
|
-
}
|
|
114
|
-
function _temp3(v) {
|
|
100
|
+
function _temp(v) {
|
|
115
101
|
return v.device;
|
|
116
102
|
}
|
|
@@ -3,6 +3,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
import throttle from 'lodash.throttle';
|
|
5
5
|
import getUserInfo from '../calls/getUserInfo';
|
|
6
|
+
import { addAppleSafeAreaListener as addNativeAppleSafeAreaListener } from '../calls/appleSafeAreaListener';
|
|
6
7
|
import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
|
|
7
8
|
import { DefaultLoginDialogOptions } from '../constants';
|
|
8
9
|
import { DefaultTrustedDomains } from '../constants/trustedDomains';
|
|
@@ -12,7 +13,6 @@ import DialogHandler from '../handler/DialogHandler';
|
|
|
12
13
|
import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
|
|
13
14
|
import { AppName, DialogButtonType, DialogType, Environment, Font, Gender, IconType, LoginState, RuntimeEnvironment, TappEvent } from '../types/IChaynsReact';
|
|
14
15
|
import invokeAppCall from '../utils/appCall';
|
|
15
|
-
import { getAppAppleSafeAreaFunctions } from '../utils/appleSafeArea';
|
|
16
16
|
import { addAppStorageListener, clearAppStorage, isAppStorageAvailable, setAppStorageItem } from '../utils/appStorage';
|
|
17
17
|
import getDeviceInfo, { getScreenSize } from '../utils/deviceHelper';
|
|
18
18
|
import { isAppCallSupported } from '../utils/is';
|
|
@@ -153,6 +153,7 @@ export class AppWrapper {
|
|
|
153
153
|
_defineProperty(this, "values", null);
|
|
154
154
|
_defineProperty(this, "history", null);
|
|
155
155
|
_defineProperty(this, "accessToken", '');
|
|
156
|
+
_defineProperty(this, "latestAppleSafeArea", null);
|
|
156
157
|
_defineProperty(this, "trustedDomains", DefaultTrustedDomains);
|
|
157
158
|
_defineProperty(this, "listeners", []);
|
|
158
159
|
_defineProperty(this, "customFunctions", {});
|
|
@@ -256,7 +257,28 @@ export class AppWrapper {
|
|
|
256
257
|
}
|
|
257
258
|
return id;
|
|
258
259
|
},
|
|
259
|
-
addAppleSafeAreaListener: callback =>
|
|
260
|
+
addAppleSafeAreaListener: async callback => {
|
|
261
|
+
const {
|
|
262
|
+
id,
|
|
263
|
+
shouldInitialize
|
|
264
|
+
} = addApiListener('appleSafeAreaListener', value => {
|
|
265
|
+
this.latestAppleSafeArea = value;
|
|
266
|
+
callback(value);
|
|
267
|
+
});
|
|
268
|
+
if (this.latestAppleSafeArea) {
|
|
269
|
+
callback(this.latestAppleSafeArea);
|
|
270
|
+
}
|
|
271
|
+
if (shouldInitialize) {
|
|
272
|
+
addNativeAppleSafeAreaListener({
|
|
273
|
+
invokeCall: this.functions.invokeCall,
|
|
274
|
+
callback: value => {
|
|
275
|
+
this.latestAppleSafeArea = value;
|
|
276
|
+
dispatchApiEvent('appleSafeAreaListener', value);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return id;
|
|
281
|
+
},
|
|
260
282
|
customCallbackFunction: async () => {
|
|
261
283
|
this.notImplemented('customCallbackFunction');
|
|
262
284
|
},
|
|
@@ -300,15 +322,22 @@ export class AppWrapper {
|
|
|
300
322
|
pageWidth: window.innerWidth,
|
|
301
323
|
topBarHeight: 0
|
|
302
324
|
}),
|
|
303
|
-
getAppleSafeArea: () =>
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
325
|
+
getAppleSafeArea: async () => {
|
|
326
|
+
if (this.latestAppleSafeArea) {
|
|
327
|
+
return this.latestAppleSafeArea;
|
|
328
|
+
}
|
|
329
|
+
let resolveValue;
|
|
330
|
+
const result = new Promise(resolve => {
|
|
331
|
+
resolveValue = resolve;
|
|
332
|
+
});
|
|
333
|
+
const id = await this.functions.addAppleSafeAreaListener(resolveValue);
|
|
334
|
+
try {
|
|
335
|
+
return await result;
|
|
336
|
+
} finally {
|
|
337
|
+
await this.functions.removeAppleSafeAreaListener(id);
|
|
311
338
|
}
|
|
339
|
+
},
|
|
340
|
+
invokeCall: async (value, callback) => {
|
|
312
341
|
return this.appCall(value.action, value.value, {
|
|
313
342
|
callback
|
|
314
343
|
});
|
|
@@ -319,7 +348,7 @@ export class AppWrapper {
|
|
|
319
348
|
});
|
|
320
349
|
},
|
|
321
350
|
invokeDialogCall: async (value, callback) => {
|
|
322
|
-
const callbackName =
|
|
351
|
+
const callbackName = this.getCallbackName();
|
|
323
352
|
window[callbackName] = ({
|
|
324
353
|
retVal
|
|
325
354
|
}) => {
|
|
@@ -448,7 +477,9 @@ export class AppWrapper {
|
|
|
448
477
|
this.resizeListener = null;
|
|
449
478
|
}
|
|
450
479
|
},
|
|
451
|
-
removeAppleSafeAreaListener: id =>
|
|
480
|
+
removeAppleSafeAreaListener: async id => {
|
|
481
|
+
removeApiListener('appleSafeAreaListener', id);
|
|
482
|
+
},
|
|
452
483
|
selectPage: async options => {
|
|
453
484
|
var _this$values, _this$values2;
|
|
454
485
|
if ((_this$values = this.values) !== null && _this$values !== void 0 && (_this$values = _this$values.site) !== null && _this$values !== void 0 && _this$values.id && options.siteId && options.siteId !== ((_this$values2 = this.values) === null || _this$values2 === void 0 || (_this$values2 = _this$values2.site) === null || _this$values2 === void 0 ? void 0 : _this$values2.id)) {
|
|
@@ -721,6 +752,13 @@ export class AppWrapper {
|
|
|
721
752
|
notImplemented(call) {
|
|
722
753
|
console.warn(`call ${call} not implement in app`);
|
|
723
754
|
}
|
|
755
|
+
getCallbackName() {
|
|
756
|
+
let callbackName;
|
|
757
|
+
do {
|
|
758
|
+
callbackName = `chaynsApiV5Callback_${this.counter++}`;
|
|
759
|
+
} while (callbackName in window);
|
|
760
|
+
return callbackName;
|
|
761
|
+
}
|
|
724
762
|
appCall(action, value = {}, {
|
|
725
763
|
callback,
|
|
726
764
|
awaitResult = true
|
|
@@ -733,7 +771,7 @@ export class AppWrapper {
|
|
|
733
771
|
return;
|
|
734
772
|
}
|
|
735
773
|
return new Promise(resolve => {
|
|
736
|
-
const callbackName =
|
|
774
|
+
const callbackName = this.getCallbackName();
|
|
737
775
|
window[callbackName] = v => {
|
|
738
776
|
var _v$retVal2;
|
|
739
777
|
if (callback) {
|
|
@@ -1,28 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addAppleSafeAreaListener as addNativeAppleSafeAreaListener } from '../calls/appleSafeAreaListener';
|
|
2
|
+
import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
|
|
2
3
|
const createAppleSafeAreaFunctions = functions => {
|
|
3
|
-
var _ref, _runtimeFunctions$add;
|
|
4
4
|
const runtimeFunctions = functions;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let latestValue = null;
|
|
6
|
+
const addAppleSafeAreaListener = callback => {
|
|
7
|
+
const handleValue = value => {
|
|
8
|
+
latestValue = value;
|
|
9
|
+
callback(value);
|
|
10
|
+
};
|
|
7
11
|
if (runtimeFunctions.addAppleSafeAreaListener) {
|
|
8
|
-
return runtimeFunctions.addAppleSafeAreaListener(
|
|
12
|
+
return runtimeFunctions.addAppleSafeAreaListener(handleValue);
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const {
|
|
15
|
+
id,
|
|
16
|
+
shouldInitialize
|
|
17
|
+
} = addApiListener('appleSafeAreaListener', handleValue);
|
|
18
|
+
if (latestValue) {
|
|
19
|
+
callback(latestValue);
|
|
14
20
|
}
|
|
15
|
-
if (runtimeFunctions.
|
|
16
|
-
|
|
21
|
+
if (shouldInitialize && runtimeFunctions.invokeCall) {
|
|
22
|
+
addNativeAppleSafeAreaListener({
|
|
23
|
+
invokeCall: runtimeFunctions.invokeCall,
|
|
24
|
+
callback: value => {
|
|
25
|
+
latestValue = value;
|
|
26
|
+
dispatchApiEvent('appleSafeAreaListener', value);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve(id);
|
|
31
|
+
};
|
|
32
|
+
const removeAppleSafeAreaListener = id => {
|
|
33
|
+
if (runtimeFunctions.addAppleSafeAreaListener) {
|
|
34
|
+
var _runtimeFunctions$rem, _runtimeFunctions$rem2;
|
|
35
|
+
return (_runtimeFunctions$rem = (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) === null || _runtimeFunctions$rem2 === void 0 ? void 0 : _runtimeFunctions$rem2.call(runtimeFunctions, id)) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
removeApiListener('appleSafeAreaListener', id);
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
};
|
|
40
|
+
const getAppleSafeArea = async () => {
|
|
41
|
+
if (latestValue) {
|
|
42
|
+
return latestValue;
|
|
43
|
+
}
|
|
44
|
+
if (!runtimeFunctions.addAppleSafeAreaListener && !runtimeFunctions.invokeCall) {
|
|
45
|
+
return {
|
|
46
|
+
top: 0,
|
|
47
|
+
left: 0,
|
|
48
|
+
bottom: 0,
|
|
49
|
+
right: 0
|
|
50
|
+
};
|
|
17
51
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
bottom: 0,
|
|
22
|
-
right: 0
|
|
52
|
+
let resolveValue;
|
|
53
|
+
const result = new Promise(resolve => {
|
|
54
|
+
resolveValue = resolve;
|
|
23
55
|
});
|
|
24
|
-
|
|
25
|
-
|
|
56
|
+
const id = await addAppleSafeAreaListener(resolveValue);
|
|
57
|
+
try {
|
|
58
|
+
return await result;
|
|
59
|
+
} finally {
|
|
60
|
+
await removeAppleSafeAreaListener(id);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
addAppleSafeAreaListener,
|
|
65
|
+
removeAppleSafeAreaListener,
|
|
66
|
+
getAppleSafeArea
|
|
67
|
+
};
|
|
26
68
|
};
|
|
27
69
|
export const normalizeFunctions = functions => {
|
|
28
70
|
var _runtimeFunctions$isT;
|
|
@@ -35,20 +77,7 @@ export const normalizeFunctions = functions => {
|
|
|
35
77
|
...functions
|
|
36
78
|
};
|
|
37
79
|
if (!hasSafeAreaFunctions) {
|
|
38
|
-
|
|
39
|
-
Object.assign(normalizedFunctions, safeAreaFunctions);
|
|
40
|
-
if (runtimeFunctions.invokeCall) {
|
|
41
|
-
const invokeCall = runtimeFunctions.invokeCall;
|
|
42
|
-
normalizedFunctions.invokeCall = async (value, callback) => {
|
|
43
|
-
if (value.action === 300) {
|
|
44
|
-
if (callback) {
|
|
45
|
-
await safeAreaFunctions.addAppleSafeAreaListener(callback);
|
|
46
|
-
}
|
|
47
|
-
return safeAreaFunctions.getAppleSafeArea();
|
|
48
|
-
}
|
|
49
|
-
return invokeCall(value, callback);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
80
|
+
Object.assign(normalizedFunctions, createAppleSafeAreaFunctions(functions));
|
|
52
81
|
}
|
|
53
82
|
normalizedFunctions.isTrustedUrl = (_runtimeFunctions$isT = runtimeFunctions.isTrustedUrl) !== null && _runtimeFunctions$isT !== void 0 ? _runtimeFunctions$isT : () => Promise.resolve(true);
|
|
54
83
|
return normalizedFunctions;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AppleSafeArea } from '../types/IChaynsReact';
|
|
1
|
+
import { AppleSafeArea, ChaynsReactFunctions } from '../types/IChaynsReact';
|
|
2
2
|
export interface AddAppleSafeAreaListenerOptions {
|
|
3
3
|
callback: (safeArea: AppleSafeArea) => void;
|
|
4
|
+
invokeCall: ChaynsReactFunctions['invokeCall'];
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Registers the native safe-area callback, preserving the complete result including optional
|
|
8
|
+
* iPhone Duo hinge metadata. Callers must use the API listener registry to share this callback.
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
export declare const addAppleSafeAreaListener: ({ callback }: AddAppleSafeAreaListenerOptions) => void;
|
|
11
|
+
export declare const addAppleSafeAreaListener: ({ callback, invokeCall }: AddAppleSafeAreaListenerOptions) => void;
|