@applicaster/zapp-react-native-utils 13.0.0-alpha.5335086935 → 13.0.0-alpha.5375459737

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 (50) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +137 -6
  2. package/actionsExecutor/consts.ts +4 -0
  3. package/appUtils/HooksManager/Hook.ts +4 -0
  4. package/appUtils/HooksManager/index.ts +3 -1
  5. package/appUtils/contextKeysManager/contextResolver.ts +1 -12
  6. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
  7. package/appUtils/focusManager/index.ts +14 -10
  8. package/appUtils/keyCodes/index.ts +11 -7
  9. package/appUtils/localizationsHelper.ts +23 -0
  10. package/appUtils/orientationHelper.ts +11 -13
  11. package/appUtils/playerManager/player.ts +24 -12
  12. package/appUtils/playerManager/playerNative.ts +18 -3
  13. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  14. package/arrayUtils/index.ts +1 -1
  15. package/componentsUtils/index.ts +18 -3
  16. package/dateUtils/index.ts +19 -0
  17. package/focusManager/FocusManager.ts +3 -1
  18. package/focusManager/index.ts +3 -21
  19. package/functionUtils/index.ts +46 -8
  20. package/index.d.ts +0 -12
  21. package/localizationUtils/index.ts +5 -10
  22. package/manifestUtils/defaultManifestConfigurations/player.js +14 -0
  23. package/manifestUtils/fonts/index.js +5 -6
  24. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +1 -1
  25. package/modalState/__tests__/index.test.ts +51 -0
  26. package/modalState/index.ts +32 -2
  27. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +1 -0
  28. package/navigationUtils/index.ts +3 -1
  29. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  30. package/numberUtils/index.ts +11 -5
  31. package/package.json +2 -6
  32. package/playerUtils/configurationGenerator.ts +14 -0
  33. package/reactHooks/advertising/index.ts +5 -5
  34. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  35. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  36. package/reactHooks/feed/useFeedLoader.tsx +17 -8
  37. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  38. package/reactHooks/navigation/__tests__/index.test.tsx +6 -17
  39. package/reactHooks/navigation/index.ts +6 -4
  40. package/reactHooks/navigation/useRoute.ts +4 -6
  41. package/services/js2native.ts +673 -0
  42. package/time/BackgroundTimer.ts +55 -0
  43. package/time/Timer.ts +6 -6
  44. package/utils/README.md +30 -0
  45. package/utils/chunk.ts +5 -0
  46. package/utils/index.ts +5 -0
  47. package/utils/times.ts +5 -0
  48. package/zappFrameworkUtils/localStorageHelper.ts +6 -0
  49. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  50. package/zappFrameworkUtils/types.ts +11 -0
@@ -8,8 +8,6 @@ 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
-
13
11
  export function useFocusManager() {
14
12
  return focusManager;
15
13
  }
@@ -76,14 +74,6 @@ export function useFocusEffect(onFocus, focusWatcher) {
76
74
  }, focusWatcher);
77
75
  }
78
76
 
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
-
87
77
  export const isFocusable = (component: ZappEntry | ZappUIComponent | any) =>
88
78
  R.tryCatch(
89
79
  R.compose(
@@ -101,6 +91,7 @@ type Props = {
101
91
 
102
92
  export const useIsFocusable = (props: Props): void => {
103
93
  const { component, zappPipesData } = props;
94
+
104
95
  const { setIsFocusable } = useFocusable();
105
96
 
106
97
  const componentCellsFocusable = toBooleanWithDefaultTrue(
@@ -119,12 +110,7 @@ export const useIsFocusable = (props: Props): void => {
119
110
 
120
111
  const hasDataError = !!zappPipesData?.error;
121
112
 
122
- const hasEmptyGroup = shouldShowEmptyGroup(component);
123
-
124
- const isGallery = component?.component_type === "gallery-qb";
125
-
126
- const isHiddenDueToEmptyData =
127
- !isLoadingData && hasNoData && hideIfDataEmpty && !hasEmptyGroup;
113
+ const isHiddenDueToEmptyData = !isLoadingData && hasNoData && hideIfDataEmpty;
128
114
 
129
115
  const defaultFocusableLogic =
130
116
  componentCellsFocusable && (!hasNoData || !hideIfDataEmpty);
@@ -133,9 +119,7 @@ export const useIsFocusable = (props: Props): void => {
133
119
  if (isAndroidTVPlatform()) {
134
120
  let isFocusableNew = false;
135
121
 
136
- if (isGallery) {
137
- isFocusableNew = true;
138
- } else if (isFocusable(component)) {
122
+ if (isFocusable(component)) {
139
123
  isFocusableNew = defaultFocusableLogic;
140
124
  }
141
125
 
@@ -144,9 +128,7 @@ export const useIsFocusable = (props: Props): void => {
144
128
  }, [
145
129
  defaultFocusableLogic,
146
130
  isHiddenDueToEmptyData,
147
- isGallery,
148
131
  setIsFocusable,
149
132
  hasDataError,
150
- hasEmptyGroup,
151
133
  ]);
152
134
  };
@@ -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
  };
@@ -245,3 +258,28 @@ export const extractDataFromProperty = (property, data): any =>
245
258
  );
246
259
 
247
260
  export const then = (fn) => (promise) => promise.then(fn);
261
+
262
+ /**
263
+ * Returns a replacer function for JSON.stringify that handles circular references,
264
+ * functions, and React context objects
265
+ * @returns {Function} A replacer function that detects and handles circular references,
266
+ * functions, and React context objects
267
+ */
268
+ export const getJsonReplacer = () => {
269
+ return (_key, value) => {
270
+ if (typeof value === "function") {
271
+ return "[Function]";
272
+ }
273
+
274
+ if (
275
+ typeof value === "object" &&
276
+ value !== null &&
277
+ value.Provider &&
278
+ value.Consumer
279
+ ) {
280
+ return "[ReactContext]";
281
+ }
282
+
283
+ return value;
284
+ };
285
+ };
package/index.d.ts CHANGED
@@ -105,18 +105,6 @@ declare type NavBarState = {
105
105
  title: string;
106
106
  };
107
107
 
108
- declare type StorageValuesToAdd = Record<string, NamespaceValues>;
109
-
110
- declare type StorageValuesToRemove = {
111
- string?: string[];
112
- };
113
-
114
- declare type StorageOwnedValues = {
115
- string?: string[];
116
- };
117
-
118
- declare type NamespaceValues = Record<string, string>;
119
-
120
108
  declare type RefreshProps = {
121
109
  forceRefresh?: boolean;
122
110
  };
@@ -1,4 +1,3 @@
1
- import * as R from "ramda";
2
1
  import { ViewStyle } from "react-native";
3
2
 
4
3
  import { useMemo } from "react";
@@ -29,14 +28,16 @@ const RTL_LOCALES = [
29
28
  "yi", // Yiddish
30
29
  ];
31
30
 
32
- export function useLocalizedStrings({ localizations }) {
31
+ export function useLocalizedStrings({ localizations = {} }) {
33
32
  const languageCode = getUILanguage();
34
33
 
35
34
  // TODO: probably we can call getLocalizations here from localizationsHelper.js
36
35
  const result = useMemo(
37
36
  () =>
38
37
  localizations?.[languageCode] ||
39
- R.compose(R.head, R.filter(R.is(Object)), R.values)(localizations) ||
38
+ Object.values(localizations).find(
39
+ (value) => typeof value === "object" && value !== null
40
+ ) ||
40
41
  {},
41
42
  [languageCode, localizations]
42
43
  );
@@ -53,13 +54,7 @@ export function getIsRTL(): boolean {
53
54
  return false;
54
55
  }
55
56
 
56
- const [languageCode] = uiLanguage.split("-");
57
-
58
- const lowerCaseLanguageCode = languageCode.toLocaleLowerCase();
59
-
60
- const isRTL = R.contains(lowerCaseLanguageCode, RTL_LOCALES);
61
-
62
- return isRTL;
57
+ return RTL_LOCALES.includes(uiLanguage.split("-")[0].toLocaleLowerCase());
63
58
  }
64
59
 
65
60
  export function useIsRTL(): boolean {
@@ -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
 
@@ -2547,6 +2555,12 @@ function getPlayerConfiguration({ platform }) {
2547
2555
  multiple: false,
2548
2556
  label_tooltip: "Choose the default aspect ratio for the artwork",
2549
2557
  },
2558
+ {
2559
+ key: "audio_player_artwork_border_radius",
2560
+ label: "Audio Player Artwork Corner Radius",
2561
+ type: "number_input",
2562
+ initial_value: 16,
2563
+ },
2550
2564
  ]
2551
2565
  )
2552
2566
  );
@@ -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
  {
@@ -0,0 +1,51 @@
1
+ import { modalStore } from "../";
2
+
3
+ describe("Modal State", () => {
4
+ it("should have initial state", () => {
5
+ const state = modalStore.getState();
6
+
7
+ expect(state).toMatchObject({
8
+ modalState: {
9
+ visible: false,
10
+ screen: null,
11
+ options: {},
12
+ props: {},
13
+ },
14
+ });
15
+
16
+ expect(state.openModal).toBeDefined();
17
+ expect(state.dismissModal).toBeDefined();
18
+ });
19
+
20
+ describe("opening and dismissing modal", () => {
21
+ it("should open modal", () => {
22
+ const item = { id: "test", name: "Test Modal" };
23
+ const options = { animated: true, animationType: "slide" };
24
+ const props = { customProp: "value" };
25
+
26
+ modalStore.getState().openModal({ item, options, props });
27
+
28
+ const state = modalStore.getState();
29
+
30
+ expect(state.modalState).toMatchObject({
31
+ visible: true,
32
+ screen: item,
33
+ options,
34
+ props,
35
+ });
36
+ });
37
+
38
+ it("should dismiss modal", () => {
39
+ modalStore.getState().dismissModal();
40
+
41
+ const state = modalStore.getState();
42
+
43
+ expect(state.modalState).toMatchObject({
44
+ visible: false,
45
+ screen: null,
46
+ options: {},
47
+ props: {},
48
+ });
49
+ });
50
+ });
51
+ });
@@ -1,4 +1,4 @@
1
- import { create } from "zustand";
1
+ import { useStore, createStore } from "zustand";
2
2
 
3
3
  interface ModalState {
4
4
  visible: boolean;
@@ -25,7 +25,7 @@ const initialModalState: ModalState = {
25
25
  props: {},
26
26
  };
27
27
 
28
- export const useModalStore = create<ModalStore>((set) => ({
28
+ export const modalStore = createStore<ModalStore>((set) => ({
29
29
  modalState: initialModalState,
30
30
  setModalState: (newState) =>
31
31
  set((state) => ({
@@ -51,3 +51,33 @@ export const useModalStore = create<ModalStore>((set) => ({
51
51
  }),
52
52
  dismissModal: () => set(() => ({ modalState: initialModalState })),
53
53
  }));
54
+
55
+ export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
56
+ useStore(modalStore, selector);
57
+
58
+ export const openModal = modalStore.getInitialState().openModal;
59
+
60
+ export const dismissModal = modalStore.getInitialState().dismissModal;
61
+
62
+ export const openBottomSheetModal = ({
63
+ ModalBottomSheetContent,
64
+ modalBottomSheetContentProps,
65
+ props = {},
66
+ options = {},
67
+ }: OpenModalBottomSheetArgs) => {
68
+ openModal({
69
+ item: {
70
+ ModalBottomSheetContent,
71
+ modalBottomSheetContentProps,
72
+ },
73
+ props,
74
+ options: {
75
+ animationType: "none",
76
+ animated: false,
77
+ ...options,
78
+ },
79
+ });
80
+ };
81
+
82
+ export const useModalStoreState = (): ModalState =>
83
+ useModalStore<ModalState>((state) => state.modalState);
@@ -5,6 +5,7 @@ exports[`getNavigationProps returns the props otherwise 1`] = `
5
5
  "assets": {
6
6
  "appLogo": "appLogo.png",
7
7
  },
8
+ "data": undefined,
8
9
  "home": false,
9
10
  "nav_items": [
10
11
  {
@@ -111,6 +111,7 @@ export function getNavigationProps({
111
111
  assets: ZappNavBarAssets;
112
112
  rules: ZappNavBarRules;
113
113
  nav_items: NavBarItem[];
114
+ data: MenuItemDataProperties;
114
115
  } | null {
115
116
  const { activeRiver } = navigator;
116
117
  const { navigations, id: selected, home } = activeRiver; // use useRiver hook instead
@@ -124,7 +125,7 @@ export function getNavigationProps({
124
125
  return null;
125
126
  }
126
127
 
127
- const { styles, assets, nav_items, rules } = navigation;
128
+ const { styles, assets, nav_items, rules, data } = navigation;
128
129
 
129
130
  return {
130
131
  selected,
@@ -134,6 +135,7 @@ export function getNavigationProps({
134
135
  assets: assets as ZappNavBarAssets,
135
136
  nav_items: nav_items as any as NavBarItem[],
136
137
  rules: rules as any as ZappNavBarRules,
138
+ data: data as MenuItemDataProperties,
137
139
  };
138
140
  }
139
141
 
@@ -1,10 +1,10 @@
1
1
  import { toPositiveNumberWithDefault } from "..";
2
2
 
3
- describe("toNumber", () => {
3
+ describe("toPositiveNumberWithDefault", () => {
4
4
  const DEFAULT = 5;
5
5
 
6
6
  it("return number if input is positive number", () => {
7
- const inputs = [0, 1, 2, 100, 200.12, Infinity];
7
+ const inputs = [1, 2, 100, 200.12, Infinity];
8
8
  expect.assertions(inputs.length);
9
9
 
10
10
  inputs.forEach((input) => {
@@ -14,7 +14,7 @@ describe("toNumber", () => {
14
14
  });
15
15
 
16
16
  it("return number if input is positive number as string", () => {
17
- const inputs = ["0", "1", "2", "100", "200.12"];
17
+ const inputs = ["1", "2", "100", "200.12"];
18
18
  expect.assertions(inputs.length);
19
19
 
20
20
  inputs.forEach((input) => {
@@ -63,4 +63,24 @@ describe("toNumber", () => {
63
63
  expect(output).toBe(DEFAULT);
64
64
  });
65
65
  });
66
+
67
+ it("return default if input is zero number", () => {
68
+ const inputs = [0, -0];
69
+ expect.assertions(inputs.length);
70
+
71
+ inputs.forEach((input) => {
72
+ const output = toPositiveNumberWithDefault(DEFAULT, input);
73
+ expect(output).toBe(DEFAULT);
74
+ });
75
+ });
76
+
77
+ it("return default if input is zero string", () => {
78
+ const inputs = ["0", "-0"];
79
+ expect.assertions(inputs.length);
80
+
81
+ inputs.forEach((input) => {
82
+ const output = toPositiveNumberWithDefault(DEFAULT, input);
83
+ expect(output).toBe(DEFAULT);
84
+ });
85
+ });
66
86
  });
@@ -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
 
@@ -81,6 +83,10 @@ export const toPositiveNumberWithDefault = (
81
83
  return defaultValue;
82
84
  }
83
85
 
86
+ if (isZero(possibleNumber)) {
87
+ return defaultValue;
88
+ }
89
+
84
90
  return possibleNumber;
85
91
  };
86
92
 
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-alpha.5335086935",
3
+ "version": "13.0.0-alpha.5375459737",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "test": "jest -w=2",
9
8
  "build": "echo skipping hybrid ts build in main packages for now"
10
9
  },
11
10
  "publishConfig": {
@@ -28,7 +27,7 @@
28
27
  },
29
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
29
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-alpha.5335086935",
30
+ "@applicaster/applicaster-types": "13.0.0-alpha.5375459737",
32
31
  "buffer": "^5.2.1",
33
32
  "camelize": "^1.0.0",
34
33
  "dayjs": "^1.11.10",
@@ -45,8 +44,5 @@
45
44
  "uglify-js": "*",
46
45
  "validate-color": "*",
47
46
  "zustand": "*"
48
- },
49
- "devDependencies": {
50
- "@types/react-native": "0.69.6"
51
47
  }
52
48
  }
@@ -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
 
@@ -2549,6 +2557,12 @@ function getPlayerConfiguration({ platform }) {
2549
2557
  multiple: false,
2550
2558
  label_tooltip: "Choose the default aspect ratio for the artwork",
2551
2559
  },
2560
+ {
2561
+ key: "audio_player_artwork_border_radius",
2562
+ label: "Audio Player Artwork Corner Radius",
2563
+ type: "number_input",
2564
+ initial_value: 16,
2565
+ },
2552
2566
  ]
2553
2567
  )
2554
2568
  );
@@ -5,6 +5,7 @@ import * as R from "ramda";
5
5
  import { useNavigation } from "../navigation";
6
6
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
7
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
8
+ import { dismissModal, openModal } from "../../modalState";
8
9
 
9
10
  const GOOGLE_ADS_IDENTIFIER = "google-admob-ads-qb";
10
11
 
@@ -14,9 +15,8 @@ const ModalContainer = platformSelect({
14
15
  });
15
16
 
16
17
  export function useAdvertisingInterstitial() {
17
- const navigator = useNavigation();
18
+ const { screenData, currentRoute } = useNavigation();
18
19
  const { plugins } = usePickFromState();
19
- const { screenData } = navigator;
20
20
 
21
21
  return useEffect(() => {
22
22
  // TODD: typing problem: fix any type
@@ -26,7 +26,7 @@ export function useAdvertisingInterstitial() {
26
26
  plugins
27
27
  );
28
28
 
29
- navigator.openModal({
29
+ openModal({
30
30
  item: {},
31
31
  options: {
32
32
  ModalContainer,
@@ -36,11 +36,11 @@ export function useAdvertisingInterstitial() {
36
36
  screenType: "hooks",
37
37
  screenData: {
38
38
  payload: screenData,
39
- callback: navigator.dismissModal,
39
+ callback: dismissModal,
40
40
  hookPlugin: GoogleAdsPlugin,
41
41
  },
42
42
  },
43
43
  });
44
44
  }
45
- }, [navigator.currentRoute, screenData?.id]);
45
+ }, [currentRoute, screenData?.id]);
46
46
  }
@@ -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);