@applicaster/zapp-react-native-utils 13.0.0-alpha.3962361544 → 13.0.0-alpha.4012243505

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 (53) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +126 -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/localizationsHelper.ts +23 -0
  9. package/appUtils/orientationHelper.ts +11 -13
  10. package/appUtils/playerManager/player.ts +24 -12
  11. package/appUtils/playerManager/playerNative.ts +18 -3
  12. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  13. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  14. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  15. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  16. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  17. package/componentsUtils/index.ts +32 -0
  18. package/dateUtils/index.ts +19 -0
  19. package/focusManager/FocusManager.ts +3 -1
  20. package/focusManager/index.ts +3 -21
  21. package/functionUtils/index.ts +46 -8
  22. package/index.d.ts +0 -12
  23. package/localizationUtils/index.ts +5 -10
  24. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  25. package/manifestUtils/defaultManifestConfigurations/player.js +14 -0
  26. package/manifestUtils/keys.js +9 -0
  27. package/modalState/__tests__/index.test.ts +51 -0
  28. package/modalState/index.ts +32 -2
  29. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +1 -0
  30. package/navigationUtils/index.ts +3 -1
  31. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  32. package/numberUtils/index.ts +11 -5
  33. package/package.json +2 -6
  34. package/playerUtils/configurationGenerator.ts +14 -0
  35. package/reactHooks/advertising/index.ts +5 -5
  36. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +5 -7
  37. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  38. package/reactHooks/feed/useFeedLoader.tsx +17 -8
  39. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  40. package/reactHooks/navigation/__tests__/index.test.tsx +0 -11
  41. package/reactHooks/navigation/index.ts +5 -3
  42. package/reactHooks/navigation/useRoute.ts +4 -6
  43. package/reactHooks/useListenEventBusEvent.ts +1 -1
  44. package/services/js2native.ts +673 -0
  45. package/time/BackgroundTimer.ts +55 -0
  46. package/time/Timer.ts +6 -6
  47. package/utils/README.md +30 -0
  48. package/utils/chunk.ts +5 -0
  49. package/utils/index.ts +5 -0
  50. package/utils/times.ts +5 -0
  51. package/zappFrameworkUtils/localStorageHelper.ts +6 -0
  52. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  53. package/zappFrameworkUtils/types.ts +11 -0
@@ -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 @@ import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
5
  import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux/hooks";
6
6
 
7
7
  import { reactHooksLogger } from "../logger";
8
- import { useIsInitialRender, shouldDispatchData } from "../utils";
8
+ import { shouldDispatchData, useIsInitialRender } from "../utils";
9
9
  import { useInflatedUrl } from "./useInflatedUrl";
10
10
  import { useRoute } from "../navigation";
11
11
 
@@ -20,6 +20,7 @@ type Props = {
20
20
  silentRefresh?: boolean;
21
21
  method?: "get" | "post";
22
22
  bodyParams?: Record<string, unknown>;
23
+ skipLoading?: boolean;
23
24
  };
24
25
  };
25
26
 
@@ -55,7 +56,9 @@ export const useFeedLoader = ({
55
56
 
56
57
  const currentFeed = useZappPipesFeed(callableFeedUrl);
57
58
 
58
- const riverId = screenData?.id;
59
+ const riverId =
60
+ (screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
61
+ screenData?.id;
59
62
 
60
63
  const reloadData = React.useCallback<ReloadDataFunction>(
61
64
  (silentRefresh = true, callback) => {
@@ -93,7 +96,7 @@ export const useFeedLoader = ({
93
96
  if (
94
97
  shouldDispatchData(callableFeedUrl, currentFeed, pipesOptions.clearCache)
95
98
  ) {
96
- if (callableFeedUrl) {
99
+ if (callableFeedUrl && !pipesOptions.skipLoading) {
97
100
  dispatch(
98
101
  loadPipesData(callableFeedUrl, {
99
102
  ...pipesOptions,
@@ -101,26 +104,33 @@ export const useFeedLoader = ({
101
104
  riverId,
102
105
  })
103
106
  );
104
- } else {
107
+ } else if (!callableFeedUrl) {
105
108
  logger.info({
106
109
  message:
107
110
  "Feed is not defined or not inflated, skipping loading. \nMake sure you have correct feedUrl and mapping.",
108
111
  jsOnly: true,
109
112
  });
113
+ } else {
114
+ logger.info({
115
+ message:
116
+ "Loading skipped as per pipesOptions.skipLoading configuration.",
117
+ data: { url: callableFeedUrl },
118
+ jsOnly: true,
119
+ });
110
120
  }
111
121
  } else {
112
122
  logger.info({
113
123
  message:
114
- "Feed already exist, skipping loading. \nCall reloadData() if you want to refresh data.",
124
+ "Feed already exists, skipping loading. \nCall reloadData() if you want to refresh data.",
115
125
  data: { url: callableFeedUrl },
116
126
  jsOnly: true,
117
127
  });
118
128
  }
119
129
  }, []);
120
130
 
121
- // Reload feed when feedUrl changes
131
+ // Reload feed when feedUrl changes, unless skipLoading is true
122
132
  useEffect(() => {
123
- if (!isInitialRender && callableFeedUrl) {
133
+ if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
124
134
  dispatch(loadPipesData(callableFeedUrl, { ...pipesOptions, riverId }));
125
135
  }
126
136
  }, [callableFeedUrl]);
@@ -156,7 +166,6 @@ export const useFeedLoader = ({
156
166
  currentFeed?.data,
157
167
  currentFeed?.error,
158
168
  currentFeed?.loading,
159
-
160
169
  reloadData,
161
170
  loadNext,
162
171
  ]);
@@ -0,0 +1,39 @@
1
+ import { reactHooksLogger } from "../../logger";
2
+ import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
3
+
4
+ const logger = reactHooksLogger.addSubsystem("useHookModalScreenData");
5
+
6
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
7
+
8
+ export const useHookModalScreenData = (): VariousScreenData | undefined => {
9
+ const hookModalState = useZappHooksModalState();
10
+
11
+ if (!hookModalState.state?.screenData) {
12
+ return;
13
+ }
14
+
15
+ try {
16
+ const screenData = hookModalState.state.screenData?.payload;
17
+ const hookPlugin = hookModalState.state.screenData.hookPlugin;
18
+
19
+ if (hookPlugin?.screen_id) {
20
+ return {
21
+ ...screenData,
22
+ targetScreen: hookPlugin,
23
+ };
24
+ }
25
+
26
+ return hookModalState.state.screenData?.payload;
27
+ } catch (error) {
28
+ logger.error({
29
+ message: "Hook modal screen data creation failed",
30
+ data: {
31
+ error,
32
+ hookModalState,
33
+ },
34
+ jsOnly: true,
35
+ });
36
+
37
+ return hookModalState.state.screenData?.payload;
38
+ }
39
+ };
@@ -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(false);
379
- });
380
369
  });
381
370
  });
@@ -108,9 +108,11 @@ export function isNavBarVisible(
108
108
  return false;
109
109
  }
110
110
 
111
- const showSecondaryLevel = screenData?.navigations?.some(
112
- (navigation) => navigation.styles?.show_secondary_level_menu
113
- );
111
+ const showSecondaryLevel =
112
+ !isTV() ||
113
+ screenData?.navigations?.some(
114
+ (navigation) => navigation.styles?.show_secondary_level_menu
115
+ );
114
116
 
115
117
  if (canGoBack && !showSecondaryLevel) {
116
118
  return false;
@@ -7,12 +7,11 @@ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
7
 
8
8
  import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
9
9
 
10
- import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
11
-
12
10
  import { getTargetScreenData } from "../screen/useTargetScreenData";
11
+ import { useHookModalScreenData } from "../hookModal/hooks/useHookModalScreenData";
13
12
 
14
13
  import { useNavigation } from "./useNavigation";
15
- import { useModalStore } from "../../modalState";
14
+ import { useModalStoreState } from "../../modalState";
16
15
  import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
17
16
  import { usePathname } from "./usePathname";
18
17
 
@@ -44,12 +43,11 @@ export const useRoute = (): {
44
43
  "contentTypes",
45
44
  ]);
46
45
 
47
- const { modalState } = useModalStore();
48
- const hookModalState = useZappHooksModalState();
46
+ const modalState = useModalStoreState();
49
47
 
50
48
  const modalScreenData = modalState.screen;
51
49
 
52
- const hookModalScreenData = hookModalState.state.screenData?.payload;
50
+ const hookModalScreenData = useHookModalScreenData();
53
51
 
54
52
  const videoModalScreenData =
55
53
  navigator?.videoModalState?.item &&
@@ -23,5 +23,5 @@ export const useListenEventBusEvent = (
23
23
  sub.remove(); // stop listening to DeviceEventEmitter
24
24
  };
25
25
  }
26
- }, []);
26
+ }, [handler, subscriptionID, source, events]);
27
27
  };