@applicaster/zapp-react-native-utils 13.0.0-alpha.7222542422 → 13.0.0-alpha.7223143213

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.
Files changed (70) hide show
  1. package/README.md +0 -10
  2. package/analyticsUtils/currentScreenProperities.ts +6 -4
  3. package/appUtils/HooksManager/Hook.ts +2 -2
  4. package/appUtils/HooksManager/index.ts +1 -1
  5. package/appUtils/HooksManager/types.ts +2 -2
  6. package/appUtils/contextKeysManager/contextResolver.ts +6 -2
  7. package/appUtils/contextKeysManager/index.ts +2 -2
  8. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  9. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
  10. package/appUtils/focusManager/index.ts +11 -12
  11. package/appUtils/keyCodes/index.ts +11 -7
  12. package/appUtils/orientationHelper.ts +11 -13
  13. package/appUtils/platform/platformUtils.ts +30 -3
  14. package/appUtils/playerManager/index.ts +1 -1
  15. package/appUtils/playerManager/player.ts +6 -2
  16. package/appUtils/playerManager/playerNative.ts +6 -2
  17. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  18. package/equalUtils/index.ts +49 -30
  19. package/focusManager/FocusManager.ts +11 -1
  20. package/focusManager/index.ts +41 -4
  21. package/functionUtils/index.ts +21 -8
  22. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  23. package/idleUtils/index.ts +1 -1
  24. package/idleUtils/withTimeout.ts +15 -2
  25. package/manifestUtils/__tests__/createConfig.test.js +0 -2
  26. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  27. package/manifestUtils/fonts/index.js +5 -6
  28. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +1 -1
  29. package/navigationUtils/index.ts +3 -3
  30. package/numberUtils/index.ts +7 -5
  31. package/package.json +4 -9
  32. package/playerUtils/configurationGenerator.ts +8 -0
  33. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  34. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  35. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  36. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  37. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  38. package/reactHooks/navigation/__tests__/index.test.tsx +6 -17
  39. package/reactHooks/navigation/index.ts +10 -22
  40. package/reactHooks/navigation/useGetTabBarHeight.ts +1 -3
  41. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  42. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  43. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  44. package/reactHooks/usePluginConfiguration.ts +1 -1
  45. package/reactHooks/useSubscriberFor.ts +4 -3
  46. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  47. package/reactUtils/__tests__/reactUtils.test.js +1 -19
  48. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  49. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +6 -72
  50. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  51. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  52. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  53. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  54. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  55. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  56. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  57. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  58. package/reactUtils/createContext/helpers.ts +6 -1
  59. package/reactUtils/createContext/index.ts +11 -25
  60. package/reactUtils/index.ts +0 -11
  61. package/screenState/index.ts +24 -10
  62. package/services/js2native.ts +673 -0
  63. package/testUtils/index.tsx +0 -10
  64. package/theme/index.ts +1 -1
  65. package/time/BackgroundTimer.ts +55 -0
  66. package/time/Timer.ts +9 -6
  67. package/types.ts +1 -0
  68. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  69. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  70. /package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +0 -0
@@ -1,6 +1,8 @@
1
1
  /* eslint no-console: off */
2
2
 
3
- import * as R from "ramda";
3
+ import { equals } from "ramda";
4
+
5
+ const alwaysTrue = () => true;
4
6
 
5
7
  export const isParentFocusEqual = (
6
8
  prevParentFocus: ParentFocus,
@@ -18,7 +20,7 @@ export const isEqual =
18
20
  ({
19
21
  byValue = [],
20
22
  byReference = [],
21
- byComparator = { comparator: R.always(true), keys: [] },
23
+ byComparator = { comparator: alwaysTrue, keys: [] },
22
24
  debug = false,
23
25
  compareRemainingKeysBySameValue = false,
24
26
  }: {
@@ -29,42 +31,59 @@ export const isEqual =
29
31
  compareRemainingKeysBySameValue?: boolean;
30
32
  }) =>
31
33
  (prev, next) => {
32
- const isEqualByValue = R.isEmpty(byValue)
33
- ? true
34
- : R.all((key) => R.equals(prev[key], next[key]), byValue);
34
+ for (const key of byReference) {
35
+ if (prev[key] !== next[key]) {
36
+ if (debug) console.log({ isEqualByReference: false });
35
37
 
36
- const isEqualByReference = R.isEmpty(byReference)
37
- ? true
38
- : R.all((key) => prev[key] === next[key], byReference);
38
+ return false;
39
+ }
40
+ }
39
41
 
40
- const isEqualByComparator = R.isEmpty(byComparator.keys)
41
- ? true
42
- : R.all(
43
- (key) => byComparator.comparator(prev[key], next[key]),
44
- byComparator.keys
45
- );
42
+ for (const key of byValue) {
43
+ if (!equals(prev[key], next[key])) {
44
+ if (debug) console.log({ isEqualByValue: false });
46
45
 
47
- if (debug) {
48
- console.log({ isEqualByValue, isEqualByReference, isEqualByComparator });
46
+ return false;
47
+ }
48
+ }
49
+
50
+ for (const key of byComparator.keys) {
51
+ if (!byComparator.comparator(prev[key], next[key])) {
52
+ if (debug) console.log({ isEqualByComparator: false });
53
+
54
+ return false;
55
+ }
49
56
  }
50
57
 
51
58
  if (compareRemainingKeysBySameValue) {
52
- const undeclaredKeys = R.difference(
53
- [...byValue, ...byReference, byComparator.keys],
54
- Object.keys(prev)
55
- );
59
+ const allKeys = new Set([...Object.keys(prev), ...Object.keys(next)]);
60
+
61
+ const declaredKeys = new Set([
62
+ ...byValue,
63
+ ...byReference,
64
+ ...byComparator.keys,
65
+ ]);
56
66
 
57
- const isRestKeysEqualAllBySameValue = undeclaredKeys.every((key) =>
58
- Object.is(prev[key], next[key])
59
- );
67
+ for (const key of Array.from(allKeys)) {
68
+ if (!declaredKeys.has(key) && !Object.is(prev[key], next[key])) {
69
+ if (debug) console.log({ isRestKeysEqualAllBySameValue: false });
60
70
 
61
- return (
62
- isEqualByValue &&
63
- isEqualByReference &&
64
- isEqualByComparator &&
65
- isRestKeysEqualAllBySameValue
66
- );
71
+ return false;
72
+ }
73
+ }
74
+ }
75
+
76
+ // if we made it here, everything matched
77
+ if (debug) {
78
+ console.log({
79
+ isEqualByValue: true,
80
+ isEqualByReference: true,
81
+ isEqualByComparator: true,
82
+ isRestKeysEqualAllBySameValue: compareRemainingKeysBySameValue
83
+ ? true
84
+ : undefined,
85
+ });
67
86
  }
68
87
 
69
- return isEqualByValue && isEqualByReference && isEqualByComparator;
88
+ return true;
70
89
  };
@@ -250,7 +250,17 @@ class FocusManager {
250
250
  }
251
251
 
252
252
  onDisableFocusChange = (id) => {
253
- if (FocusManager.instance.isFocused(id)) {
253
+ const isFocused = FocusManager.instance.isFocused(id);
254
+
255
+ const isDescendantFocused = (() => {
256
+ try {
257
+ return FocusManager.instance.isAnyDescendantFocused(id);
258
+ } catch (_e) {
259
+ return false;
260
+ }
261
+ })();
262
+
263
+ if (isFocused || isDescendantFocused) {
254
264
  // Move focus to next one
255
265
  const nextFocus = FocusManager.instance.focused?.props
256
266
  ?.nextFocusDown as string;
@@ -8,6 +8,8 @@ import { isNilOrEmpty } from "../reactUtils/helpers";
8
8
  import { isAndroidTVPlatform } from "../reactUtils";
9
9
  import { noop } from "../functionUtils";
10
10
 
11
+ const EMPTY_GROUP_COMPONENT = "empty_group_component";
12
+
11
13
  export function useFocusManager() {
12
14
  return focusManager;
13
15
  }
@@ -74,6 +76,14 @@ export function useFocusEffect(onFocus, focusWatcher) {
74
76
  }, focusWatcher);
75
77
  }
76
78
 
79
+ export function shouldShowEmptyGroup(component) {
80
+ return (
81
+ component?.ui_components?.filter(
82
+ ({ component_type }) => component_type === EMPTY_GROUP_COMPONENT
83
+ )?.length > 0
84
+ );
85
+ }
86
+
77
87
  export const isFocusable = (component: ZappEntry | ZappUIComponent | any) =>
78
88
  R.tryCatch(
79
89
  R.compose(
@@ -101,15 +111,42 @@ export const useIsFocusable = (props: Props): void => {
101
111
  component.rules.hide_component_if_data_is_empty
102
112
  );
103
113
 
114
+ const isLoadingData = !!zappPipesData?.loading;
115
+
104
116
  const hasNoData =
105
117
  isNilOrEmpty(zappPipesData?.data) ||
106
118
  isNilOrEmpty(zappPipesData?.data?.entry);
107
119
 
120
+ const hasDataError = !!zappPipesData?.error;
121
+
122
+ const hasEmptyGroup = shouldShowEmptyGroup(component);
123
+
124
+ const isGallery = component?.component_type === "gallery-qb";
125
+
126
+ const isHiddenDueToEmptyData =
127
+ !isLoadingData && hasNoData && hideIfDataEmpty && !hasEmptyGroup;
128
+
129
+ const defaultFocusableLogic =
130
+ componentCellsFocusable && (!hasNoData || !hideIfDataEmpty);
131
+
108
132
  React.useEffect(() => {
109
133
  if (isAndroidTVPlatform()) {
110
- setIsFocusable(
111
- componentCellsFocusable && (!hasNoData || !hideIfDataEmpty)
112
- );
134
+ let isFocusableNew = false;
135
+
136
+ if (isGallery) {
137
+ isFocusableNew = true;
138
+ } else if (isFocusable(component)) {
139
+ isFocusableNew = defaultFocusableLogic;
140
+ }
141
+
142
+ setIsFocusable(isFocusableNew);
113
143
  }
114
- }, [setIsFocusable, componentCellsFocusable, hasNoData]);
144
+ }, [
145
+ defaultFocusableLogic,
146
+ isHiddenDueToEmptyData,
147
+ isGallery,
148
+ setIsFocusable,
149
+ hasDataError,
150
+ hasEmptyGroup,
151
+ ]);
115
152
  };
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { useRef } from "react";
2
+ import { useCallback, useEffect, useRef } from "react";
3
3
 
4
4
  /**
5
5
  *
@@ -9,31 +9,44 @@ import { useRef } from "react";
9
9
  */
10
10
  export const useThrottle = (callback: () => void, delay: number) => {
11
11
  const lastCallRef = useRef<number>(0);
12
- const timeoutRef = useRef<any | null>(null);
12
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
13
+ const callbackRef = useRef<() => void>(callback);
13
14
 
14
- const throttledFunction = () => {
15
+ useEffect(() => {
16
+ callbackRef.current = callback;
17
+ }, [callback]);
18
+
19
+ const throttledFunction = useCallback(() => {
15
20
  const now = Date.now();
16
21
 
17
22
  if (now - lastCallRef.current >= delay) {
18
- callback();
23
+ callbackRef.current();
19
24
  lastCallRef.current = now;
20
25
  } else if (!timeoutRef.current) {
21
26
  const remainingTime = delay - (now - lastCallRef.current);
22
27
 
23
28
  timeoutRef.current = setTimeout(() => {
24
- callback();
29
+ callbackRef.current();
25
30
  lastCallRef.current = Date.now();
26
31
  timeoutRef.current = null;
27
32
  }, remainingTime);
28
33
  }
29
- };
34
+ }, [delay]);
30
35
 
31
- const cancel = () => {
36
+ const cancel = useCallback(() => {
32
37
  if (timeoutRef.current) {
33
38
  clearTimeout(timeoutRef.current);
34
39
  timeoutRef.current = null;
35
40
  }
36
- };
41
+ }, []);
42
+
43
+ useEffect(() => {
44
+ return () => {
45
+ if (timeoutRef.current) {
46
+ clearTimeout(timeoutRef.current);
47
+ }
48
+ };
49
+ }, []);
37
50
 
38
51
  return { throttledFunction, cancel };
39
52
  };
@@ -0,0 +1,37 @@
1
+ import { TestScheduler } from "rxjs/testing";
2
+
3
+ import { withTimeout$ } from "..";
4
+
5
+ describe("withTimeout$", () => {
6
+ let testScheduler: TestScheduler;
7
+
8
+ beforeEach(() => {
9
+ testScheduler = new TestScheduler((actual, expected) => {
10
+ expect(actual).toEqual(expected);
11
+ });
12
+ });
13
+
14
+ it("should emit undefined after the specified timeout", () => {
15
+ testScheduler.run(({ expectObservable }) => {
16
+ const timeout = 1000;
17
+ const expectedMarble = "1s (a|)";
18
+ const expectedValues = { a: undefined };
19
+
20
+ const result$ = withTimeout$(timeout);
21
+
22
+ expectObservable(result$).toBe(expectedMarble, expectedValues);
23
+ });
24
+ });
25
+
26
+ it("should complete after emitting undefined", () => {
27
+ testScheduler.run(({ expectObservable }) => {
28
+ const timeout = 500;
29
+ const expectedMarble = "500ms (a|)";
30
+ const expectedValues = { a: undefined };
31
+
32
+ const result$ = withTimeout$(timeout);
33
+
34
+ expectObservable(result$).toBe(expectedMarble, expectedValues);
35
+ });
36
+ });
37
+ });
@@ -1,4 +1,4 @@
1
- export { withTimeout } from "./withTimeout";
1
+ export { withTimeout, withTimeout$ } from "./withTimeout";
2
2
 
3
3
  export { onIdle } from "./onIdle";
4
4
 
@@ -1,7 +1,20 @@
1
- export const withTimeout = (timeout: number) => {
2
- return new Promise((resolve) => {
1
+ import { of, Observable } from "rxjs";
2
+ import { delay } from "rxjs/operators";
3
+
4
+ export const withTimeout = (timeout: number): Promise<void> => {
5
+ return new Promise<void>((resolve) => {
3
6
  setTimeout(() => {
4
7
  resolve(undefined);
5
8
  }, timeout);
6
9
  });
7
10
  };
11
+
12
+ /**
13
+ * Creates an observable that emits a single value after a specified timeout.
14
+ *
15
+ * @param timeout - The delay duration in milliseconds before emitting the value.
16
+ * @returns An observable that emits `undefined` after the specified timeout.
17
+ */
18
+ export const withTimeout$ = (timeout: number): Observable<void> => {
19
+ return of(undefined).pipe(delay(timeout));
20
+ };
@@ -78,8 +78,6 @@ describe("createConfig", () => {
78
78
  extend: "styles",
79
79
  })(props);
80
80
 
81
- console.log(mockGenerators.styles.mock.calls);
82
-
83
81
  expect(mockGenerators.styles).toBeCalledWith(props);
84
82
  });
85
83
 
@@ -50,6 +50,14 @@ function getPlayerConfiguration({ platform }) {
50
50
  label_tooltip:
51
51
  "Set the query params which control the size of the image e.g width, height. This will help to optimize the loading time, when magic background is enabled.",
52
52
  },
53
+ {
54
+ key: "audio_player_background_image_default_color",
55
+ label: "Audio Player Background Image Default Color",
56
+ initial_value: "",
57
+ type: "text_input",
58
+ label_tooltip:
59
+ "Set the default color for the audio player background image if not image or set of gradient colors are not provided.",
60
+ },
53
61
  ],
54
62
  };
55
63
 
@@ -224,12 +224,11 @@ function fontKey(label, defaults, conditionalField = null) {
224
224
  return fields;
225
225
  }
226
226
 
227
- function tvMenuLabel(label, description, defaults) {
228
- return fieldsGroup(
229
- label,
230
- description,
231
- generateFieldsFromDefaults(label, defaults, TV_MENU_LABEL_FIELDS)
232
- );
227
+ function tvMenuLabel(label, description, defaults, fields = []) {
228
+ return fieldsGroup(label, description, [
229
+ ...fields,
230
+ ...generateFieldsFromDefaults(label, defaults, TV_MENU_LABEL_FIELDS),
231
+ ]);
233
232
  }
234
233
 
235
234
  function mobileCellLabel(label, description, defaults, groupFolded) {
@@ -24,7 +24,7 @@ const componentConfigurationFields = [
24
24
  initial_value: "vertical",
25
25
  options: [
26
26
  { text: "Vertical", value: "vertical" },
27
- { text: "Horizontal (Beta)", value: "horizontal" },
27
+ { text: "Horizontal", value: "horizontal" },
28
28
  ],
29
29
  },
30
30
  {
@@ -644,8 +644,8 @@ export const getScreenId = (
644
644
  fallbackRiver: ZappRiver
645
645
  ) => {
646
646
  return screenData?.targetScreen
647
- ? screenData?.targetScreen?.id ?? fallbackRiver.id
647
+ ? (screenData?.targetScreen?.id ?? fallbackRiver.id)
648
648
  : "screen_id" in screenData
649
- ? screenData.screen_id
650
- : fallbackRiver.id;
649
+ ? screenData.screen_id
650
+ : fallbackRiver.id;
651
651
  };
@@ -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: any): number | undefined => {
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 = (defaultValue: number, value: any): number =>
21
- toNumber(value) ?? defaultValue;
20
+ export const toNumberWithDefault = (
21
+ defaultValue: number,
22
+ value: unknown
23
+ ): number => toNumber(value) ?? defaultValue;
22
24
 
23
- export const toNumberWithDefaultZero = (value: any): number =>
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: any
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.7222542422",
3
+ "version": "13.0.0-alpha.7223143213",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,11 +28,9 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-alpha.7222542422",
31
+ "@applicaster/applicaster-types": "13.0.0-alpha.7223143213",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
- "create-react-context": "^0.2.3",
35
- "create-react-ref": "^0.1.0",
36
34
  "dayjs": "^1.11.10",
37
35
  "memoizee": "0.4.15",
38
36
  "prop-types": "^15.0.0",
@@ -42,13 +40,10 @@
42
40
  "@applicaster/zapp-pipes-v2-client": "*",
43
41
  "@react-native-community/netinfo": "*",
44
42
  "immer": "*",
45
- "react": "17.0.2",
46
- "react-native": "0.68.6",
43
+ "react": "*",
44
+ "react-native": "*",
47
45
  "uglify-js": "*",
48
46
  "validate-color": "*",
49
47
  "zustand": "*"
50
- },
51
- "devDependencies": {
52
- "@types/react-native": "0.69.6"
53
48
  }
54
49
  }
@@ -55,6 +55,14 @@ function getPlayerConfiguration({ platform }) {
55
55
  label_tooltip:
56
56
  "Set the query params which control the size of the image e.g width, height. This will help to optimize the loading time, when magic background is enabled.",
57
57
  },
58
+ {
59
+ key: "audio_player_background_image_default_color",
60
+ label: "Audio Player Background Image Default Color",
61
+ initial_value: "",
62
+ type: "text_input",
63
+ label_tooltip:
64
+ "Set the default color for the audio player background image if not image or set of gradient colors are not provided.",
65
+ },
58
66
  ],
59
67
  };
60
68
 
@@ -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", async () => {
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
- jest.advanceTimersByTime(3000);
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);
@@ -5,7 +5,7 @@ const mockDimensionsGet = jest.fn(
5
5
  ({
6
6
  window: { width: 1, height: 1 },
7
7
  screen: { width: 360, height: 540 },
8
- }[type])
8
+ })[type]
9
9
  );
10
10
 
11
11
  ReactNative.Dimensions.get = mockDimensionsGet;
@@ -52,6 +52,14 @@ export const useDimensions: UseDimensions = (
52
52
  ? { fullDimensions }
53
53
  : { ...fullDimensions };
54
54
 
55
+ if (options.updateForInactiveScreens === undefined) {
56
+ options.updateForInactiveScreens = true;
57
+ }
58
+
59
+ if (options.fullDimensions === undefined) {
60
+ options.fullDimensions = false;
61
+ }
62
+
55
63
  const [dimensions, setDimensions] = useState(getInitialDimensions(context));
56
64
  const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
57
65
 
@@ -3,5 +3,8 @@ export const useNavigation = jest.fn(() => ({
3
3
  screenData: {
4
4
  name: "someName",
5
5
  },
6
+ videoModalState: {
7
+ visible: false,
8
+ },
6
9
  currentRoute: "someRoute",
7
10
  }));
@@ -310,14 +310,14 @@ describe("navigation", () => {
310
310
  expect(navBarVisible).toBe(false);
311
311
  });
312
312
 
313
- it("returns false if it's secondary nav bar and hide_secondary_level_menu is true", () => {
313
+ it("returns false if it's secondary nav bar and show_secondary_level_menu is false", () => {
314
314
  const navBarVisible = isNavBarVisible(
315
315
  "",
316
316
  {
317
317
  navigations: [
318
318
  {
319
319
  styles: {
320
- hide_secondary_level_menu: true,
320
+ show_secondary_level_menu: false,
321
321
  },
322
322
  },
323
323
  ],
@@ -329,14 +329,14 @@ describe("navigation", () => {
329
329
  expect(navBarVisible).toBe(false);
330
330
  });
331
331
 
332
- it("returns true if it's secondary nav bar and hide_secondary_level_menu is false", () => {
332
+ it("returns true if it's secondary nav bar and show_secondary_level_menu is true", () => {
333
333
  const navBarVisible = isNavBarVisible(
334
334
  "",
335
335
  {
336
336
  navigations: [
337
337
  {
338
338
  styles: {
339
- hide_secondary_level_menu: false,
339
+ show_secondary_level_menu: true,
340
340
  },
341
341
  },
342
342
  ],
@@ -348,14 +348,14 @@ describe("navigation", () => {
348
348
  expect(navBarVisible).toBe(true);
349
349
  });
350
350
 
351
- it("returns true if it's first level menu and hide_secondary_level_menu is true", () => {
351
+ it("returns true if it's first level menu and show_secondary_level_menu is false", () => {
352
352
  const navBarVisible = isNavBarVisible(
353
353
  "",
354
354
  {
355
355
  navigations: [
356
356
  {
357
357
  styles: {
358
- hide_secondary_level_menu: true,
358
+ show_secondary_level_menu: false,
359
359
  },
360
360
  },
361
361
  ],
@@ -366,16 +366,5 @@ describe("navigation", () => {
366
366
 
367
367
  expect(navBarVisible).toBe(true);
368
368
  });
369
-
370
- it("returns true otherwise", () => {
371
- const navBarVisible = isNavBarVisible(
372
- "",
373
- { navigations: [] } as any,
374
- true,
375
- true
376
- );
377
-
378
- expect(navBarVisible).toBe(true);
379
- });
380
369
  });
381
370
  });