@applicaster/zapp-react-native-utils 13.0.0-alpha.1692038547 → 13.0.0-alpha.1802439822
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/appUtils/platform/platformUtils.ts +6 -0
- package/equalUtils/index.ts +10 -3
- package/focusManager/FocusManager.ts +13 -28
- package/numberUtils/index.ts +7 -5
- package/package.json +2 -2
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
- package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
|
@@ -77,6 +77,12 @@ export class ClosedCaptioningManager {
|
|
|
77
77
|
|
|
78
78
|
private constructor() {
|
|
79
79
|
this.initialize();
|
|
80
|
+
|
|
81
|
+
window["vizioDebug"] = {
|
|
82
|
+
setCCEnabled: (isCCEnabled: boolean) => {
|
|
83
|
+
this.ccState$.next(isCCEnabled);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
static getInstance(): ClosedCaptioningManager {
|
package/equalUtils/index.ts
CHANGED
|
@@ -49,9 +49,16 @@ export const isEqual =
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (compareRemainingKeysBySameValue) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
53
|
+
|
|
54
|
+
const declaredKeys = new Set([
|
|
55
|
+
...byValue,
|
|
56
|
+
...byReference,
|
|
57
|
+
...byComparator.keys,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const undeclaredKeys = Array.from(allKeys).filter(
|
|
61
|
+
(key) => !declaredKeys.has(key)
|
|
55
62
|
);
|
|
56
63
|
|
|
57
64
|
const isRestKeysEqualAllBySameValue = undeclaredKeys.every((key) =>
|
|
@@ -227,14 +227,7 @@ class FocusManager {
|
|
|
227
227
|
|
|
228
228
|
const nextNextFocus = FocusManager.getNextFocusable(direction, nextFocus);
|
|
229
229
|
|
|
230
|
-
|
|
231
|
-
const nextNextFocusForParent =
|
|
232
|
-
FocusManager.instance.getNextFocusableForParent(direction, nextFocus);
|
|
233
|
-
|
|
234
|
-
FocusManager.instance.setFocus(nextNextFocusForParent, options);
|
|
235
|
-
} else {
|
|
236
|
-
FocusManager.instance.setFocus(nextNextFocus, options);
|
|
237
|
-
}
|
|
230
|
+
FocusManager.instance.setFocus(nextNextFocus, options);
|
|
238
231
|
} else {
|
|
239
232
|
FocusManager.instance.setFocusLocal(nextFocus);
|
|
240
233
|
|
|
@@ -257,7 +250,10 @@ class FocusManager {
|
|
|
257
250
|
}
|
|
258
251
|
|
|
259
252
|
onDisableFocusChange = (id) => {
|
|
260
|
-
if (
|
|
253
|
+
if (
|
|
254
|
+
FocusManager.instance.isFocused(id) ||
|
|
255
|
+
FocusManager.instance.hasFocusedChildren(id)
|
|
256
|
+
) {
|
|
261
257
|
// Move focus to next one
|
|
262
258
|
const nextFocus = FocusManager.instance.focused?.props
|
|
263
259
|
?.nextFocusDown as string;
|
|
@@ -274,6 +270,12 @@ class FocusManager {
|
|
|
274
270
|
}
|
|
275
271
|
};
|
|
276
272
|
|
|
273
|
+
hasFocusedChildren = (id) => {
|
|
274
|
+
return this.tree
|
|
275
|
+
.find(id)
|
|
276
|
+
?.children?.some((item) => item?.id === this.focusedId);
|
|
277
|
+
};
|
|
278
|
+
|
|
277
279
|
setFocus(
|
|
278
280
|
newFocus: FocusManager.TouchableReactRef | string,
|
|
279
281
|
options?: FocusManager.Android.CallbackOptions
|
|
@@ -314,26 +316,9 @@ class FocusManager {
|
|
|
314
316
|
return FocusManager.getNextFocusable(direction);
|
|
315
317
|
}
|
|
316
318
|
|
|
317
|
-
getNextFocusableForParent(
|
|
318
|
-
direction,
|
|
319
|
-
focusable?: FocusManager.TouchableReactRef
|
|
320
|
-
) {
|
|
321
|
-
const focusableId = focusable
|
|
322
|
-
? getFocusableId(focusable)
|
|
323
|
-
: FocusManager.instance.focusedId;
|
|
324
|
-
|
|
319
|
+
getNextFocusableForParent(direction) {
|
|
325
320
|
const focusDirection = toFocusDirection(direction);
|
|
326
|
-
const parentNode = this.tree.findParent(
|
|
327
|
-
|
|
328
|
-
const parentNodeParent = this.tree.findParent(parentNode?.id);
|
|
329
|
-
|
|
330
|
-
const hasNextFocusable = this.tree.find(
|
|
331
|
-
parentNode?.component?.current?.props[focusDirection]
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
if (!hasNextFocusable) {
|
|
335
|
-
return parentNodeParent?.component?.current?.props[focusDirection];
|
|
336
|
-
}
|
|
321
|
+
const parentNode = this.tree.findParent(FocusManager.instance.focusedId);
|
|
337
322
|
|
|
338
323
|
return parentNode?.component?.current?.props[focusDirection];
|
|
339
324
|
}
|
package/numberUtils/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { logger } from "@applicaster/zapp-react-native-utils/logger";
|
|
|
3
3
|
|
|
4
4
|
const numberUtilsLogger = logger?.addSubsystem("NumberUtils");
|
|
5
5
|
|
|
6
|
-
export const toNumber = (value:
|
|
6
|
+
export const toNumber = (value: unknown): number | undefined => {
|
|
7
7
|
if (R.isNil(value) || R.isEmpty(value)) {
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
@@ -17,10 +17,12 @@ export const toNumber = (value: any): number | undefined => {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const toNumberWithDefault = (
|
|
21
|
-
|
|
20
|
+
export const toNumberWithDefault = (
|
|
21
|
+
defaultValue: number,
|
|
22
|
+
value: unknown
|
|
23
|
+
): number => toNumber(value) ?? defaultValue;
|
|
22
24
|
|
|
23
|
-
export const toNumberWithDefaultZero = (value:
|
|
25
|
+
export const toNumberWithDefaultZero = (value: unknown): number =>
|
|
24
26
|
toNumberWithDefault(0, value);
|
|
25
27
|
|
|
26
28
|
export const requireNumber = (obj, key: string) => {
|
|
@@ -39,7 +41,7 @@ export const requireNumber = (obj, key: string) => {
|
|
|
39
41
|
|
|
40
42
|
export const toFiniteNumberWithDefault = (
|
|
41
43
|
defaultValue: number,
|
|
42
|
-
value:
|
|
44
|
+
value: unknown
|
|
43
45
|
): number => {
|
|
44
46
|
const possibleNumber = toNumberWithDefault(defaultValue, value);
|
|
45
47
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.1802439822",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "13.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.1802439822",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -35,25 +35,23 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
|
35
35
|
const { useTrackedView } = require("../useTrackedView");
|
|
36
36
|
|
|
37
37
|
describe("useTrackCurrentAutoScrollingElement", () => {
|
|
38
|
-
it("should update position for selected component",
|
|
38
|
+
it("should update position for selected component - onViewportEnter", () => {
|
|
39
39
|
const { result } = renderHook(() => useTrackedView("123"), {
|
|
40
40
|
wrapper: Wrapper,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
// Fast-forward until all timers have been executed
|
|
44
|
-
jest.advanceTimersByTime(3000);
|
|
45
|
-
|
|
46
43
|
expect(result.current.inViewPort).toBe(false);
|
|
47
44
|
|
|
48
45
|
const mockRect = {
|
|
49
46
|
rect: { left: 1, right: 1, top: 1, bottom: 1 },
|
|
50
47
|
};
|
|
51
48
|
|
|
52
|
-
act(() => {
|
|
53
|
-
result.current.onPositionUpdated(mockRect);
|
|
49
|
+
act(async () => {
|
|
50
|
+
await result.current.onPositionUpdated(mockRect);
|
|
54
51
|
});
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
// Fast-forward until all timers have been executed
|
|
54
|
+
jest.runAllTimers();
|
|
57
55
|
|
|
58
56
|
expect(result.current.inViewPort).toBe(true);
|
|
59
57
|
|
|
@@ -2,6 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
2
2
|
import { useScreenTrackedViewPositionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext";
|
|
3
3
|
import { useDimensions } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
|
|
4
4
|
import { findTrackedView } from "./utils/findTrackedView";
|
|
5
|
+
import { isNil } from "ramda";
|
|
6
|
+
import { withTimeout } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
7
|
+
|
|
8
|
+
const TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT = 500; // ms
|
|
5
9
|
|
|
6
10
|
const getNormalizedRect = (rect, componentId, screenWidth, screenHeight) => {
|
|
7
11
|
if (!rect) {
|
|
@@ -37,9 +41,16 @@ export const useTrackedView = (componentId: string) => {
|
|
|
37
41
|
);
|
|
38
42
|
|
|
39
43
|
const onPositionUpdated = useCallback(
|
|
40
|
-
({ rect }) => {
|
|
44
|
+
async ({ rect }) => {
|
|
41
45
|
const currentPosition = normalizedRect(componentId, rect);
|
|
42
46
|
|
|
47
|
+
// There is an issue on the native side where they are unable to guarantee
|
|
48
|
+
// that the order of onViewportLeave and onViewportEnter events is always correct.
|
|
49
|
+
// This workaround/hack delays the onViewportEnter event to ensure it is received last.
|
|
50
|
+
if (!isNil(currentPosition)) {
|
|
51
|
+
await withTimeout(TIMEOUT_FOR_DELAY_ON_VIEWPORT_ENTER_EVENT);
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
updateComponentsPositions(componentId, currentPosition as any);
|
|
44
55
|
|
|
45
56
|
setInViewPort(!!currentPosition);
|