@applicaster/zapp-react-native-utils 13.0.0-rc.14 → 13.0.0-rc.141

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 (185) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +214 -16
  4. package/actionsExecutor/consts.ts +4 -0
  5. package/alertUtils/alert.ts +148 -0
  6. package/alertUtils/index.ts +1 -148
  7. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  8. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  9. package/analyticsUtils/currentScreenProperities.ts +6 -4
  10. package/analyticsUtils/helpers/hooks.ts +1 -1
  11. package/appUtils/HooksManager/Hook.ts +6 -2
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
  13. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
  14. package/appUtils/HooksManager/index.ts +3 -1
  15. package/appUtils/HooksManager/types.ts +5 -2
  16. package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
  17. package/appUtils/__tests__/allZappLocales.ts +79 -0
  18. package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
  19. package/appUtils/accessibilityManager/const.ts +18 -0
  20. package/appUtils/accessibilityManager/index.ts +46 -2
  21. package/appUtils/contextKeysManager/contextResolver.ts +66 -0
  22. package/appUtils/contextKeysManager/index.ts +2 -2
  23. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  24. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +9 -6
  25. package/appUtils/focusManager/index.ios.ts +14 -4
  26. package/appUtils/focusManager/index.ts +108 -69
  27. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  28. package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
  29. package/appUtils/focusManager/utils/enums.ts +4 -0
  30. package/appUtils/focusManager/utils/index.ts +5 -0
  31. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  32. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  33. package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
  34. package/appUtils/keyCodes/index.ts +11 -7
  35. package/appUtils/keyCodes/keys/keysByPlatform.ts +4 -0
  36. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  37. package/appUtils/localizationsHelper.ts +31 -0
  38. package/appUtils/orientationHelper.ts +11 -13
  39. package/appUtils/platform/const.ts +14 -0
  40. package/appUtils/platform/platformUtils.ts +47 -4
  41. package/appUtils/playerManager/index.ts +1 -1
  42. package/appUtils/playerManager/player.ts +42 -18
  43. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
  44. package/appUtils/playerManager/playerNative.ts +18 -2
  45. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  46. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +7 -1
  47. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  48. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  49. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  50. package/arrayUtils/index.ts +7 -2
  51. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  52. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  53. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  54. package/audioPlayerUtils/assets/index.ts +2 -0
  55. package/audioPlayerUtils/index.ts +242 -0
  56. package/cellUtils/index.ts +9 -5
  57. package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
  58. package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
  59. package/componentsUtils/__tests__/isGallery.test.ts +33 -0
  60. package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
  61. package/componentsUtils/index.ts +39 -0
  62. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  63. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  64. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  65. package/configurationUtils/index.ts +63 -34
  66. package/dateUtils/index.ts +19 -0
  67. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  68. package/equalUtils/index.ts +49 -30
  69. package/focusManager/FocusManager.ts +14 -2
  70. package/focusManager/index.ts +23 -4
  71. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  72. package/functionUtils/index.ts +46 -8
  73. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  74. package/idleUtils/index.ts +1 -1
  75. package/idleUtils/withTimeout.ts +15 -2
  76. package/index.d.ts +0 -12
  77. package/localizationUtils/index.ts +8 -13
  78. package/logger/const.ts +9 -67
  79. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  80. package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
  81. package/manifestUtils/defaultManifestConfigurations/player.js +9 -3
  82. package/manifestUtils/fonts/index.js +5 -6
  83. package/manifestUtils/index.js +2 -0
  84. package/manifestUtils/keys.js +27 -2
  85. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  86. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +874 -0
  87. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  88. package/modalState/__tests__/index.test.ts +51 -0
  89. package/modalState/index.ts +32 -2
  90. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +7 -6
  91. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  92. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  93. package/navigationUtils/index.ts +6 -4
  94. package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
  95. package/numberUtils/index.ts +11 -5
  96. package/package.json +5 -10
  97. package/playerUtils/configurationGenerator.ts +9 -11
  98. package/playerUtils/index.ts +23 -0
  99. package/reactHooks/advertising/index.ts +5 -5
  100. package/reactHooks/app/useAppState.ts +2 -2
  101. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  102. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  103. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  104. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  105. package/reactHooks/cell-click/index.ts +7 -1
  106. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  107. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  108. package/reactHooks/feed/useBatchLoading.ts +12 -14
  109. package/reactHooks/feed/useFeedLoader.tsx +18 -9
  110. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  111. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  112. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +39 -0
  113. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  114. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  115. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  116. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  117. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  118. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  119. package/reactHooks/navigation/getTabBarHeight.ts +10 -0
  120. package/reactHooks/navigation/index.ts +34 -236
  121. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +19 -0
  122. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  123. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  124. package/reactHooks/navigation/useNavigationPluginData.ts +19 -0
  125. package/reactHooks/navigation/useNavigationType.ts +17 -0
  126. package/reactHooks/navigation/usePathname.ts +4 -0
  127. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  128. package/reactHooks/navigation/useRoute.ts +98 -0
  129. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  130. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  131. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  132. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  133. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  134. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  135. package/reactHooks/player/const.ts +0 -4
  136. package/reactHooks/player/index.ts +0 -6
  137. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
  138. package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
  139. package/reactHooks/state/README.md +79 -0
  140. package/reactHooks/state/ZStoreProvider.tsx +71 -0
  141. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +66 -0
  142. package/reactHooks/state/index.ts +2 -0
  143. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  144. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  145. package/reactHooks/useListenEventBusEvent.ts +1 -1
  146. package/reactHooks/usePluginConfiguration.ts +1 -1
  147. package/reactHooks/useSubscriberFor.ts +4 -3
  148. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  149. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  150. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  151. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  152. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  153. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  154. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  155. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  156. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  157. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  158. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  159. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  160. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  161. package/reactUtils/createContext/helpers.ts +6 -1
  162. package/reactUtils/createContext/index.ts +11 -25
  163. package/reactUtils/index.ts +9 -11
  164. package/screenState/index.ts +24 -10
  165. package/services/js2native.ts +673 -0
  166. package/testUtils/index.tsx +0 -10
  167. package/theme/__mocks__/index.ts +4 -0
  168. package/theme/index.ts +1 -1
  169. package/time/BackgroundTimer.ts +55 -0
  170. package/time/Timer.ts +9 -6
  171. package/typeGuards/index.ts +3 -0
  172. package/types.ts +1 -0
  173. package/utils/README.md +30 -0
  174. package/utils/chunk.ts +5 -0
  175. package/utils/index.ts +16 -0
  176. package/utils/times.ts +5 -0
  177. package/zappFrameworkUtils/localStorageHelper.ts +38 -10
  178. package/zappFrameworkUtils/loginPluginUtils.ts +6 -2
  179. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  180. package/zappFrameworkUtils/types.ts +11 -0
  181. package/reactHooks/player/useAutoSeek.tsx +0 -87
  182. package/reactHooks/player/useSeek.tsx +0 -66
  183. package/reactHooks/player/useTapSeek.tsx +0 -58
  184. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  185. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -135,10 +135,6 @@ const hookModalWrapper = ({ children }) => (
135
135
  </Provider>
136
136
  );
137
137
 
138
- jest.mock("../../../modalState", () => ({
139
- useModalStore: jest.fn(),
140
- }));
141
-
142
138
  describe("navigation", () => {
143
139
  describe("useRoute", () => {
144
140
  describe("Main stack components", () => {
@@ -314,14 +310,14 @@ describe("navigation", () => {
314
310
  expect(navBarVisible).toBe(false);
315
311
  });
316
312
 
317
- 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", () => {
318
314
  const navBarVisible = isNavBarVisible(
319
315
  "",
320
316
  {
321
317
  navigations: [
322
318
  {
323
319
  styles: {
324
- hide_secondary_level_menu: true,
320
+ show_secondary_level_menu: false,
325
321
  },
326
322
  },
327
323
  ],
@@ -333,14 +329,14 @@ describe("navigation", () => {
333
329
  expect(navBarVisible).toBe(false);
334
330
  });
335
331
 
336
- 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", () => {
337
333
  const navBarVisible = isNavBarVisible(
338
334
  "",
339
335
  {
340
336
  navigations: [
341
337
  {
342
338
  styles: {
343
- hide_secondary_level_menu: false,
339
+ show_secondary_level_menu: true,
344
340
  },
345
341
  },
346
342
  ],
@@ -352,14 +348,14 @@ describe("navigation", () => {
352
348
  expect(navBarVisible).toBe(true);
353
349
  });
354
350
 
355
- 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", () => {
356
352
  const navBarVisible = isNavBarVisible(
357
353
  "",
358
354
  {
359
355
  navigations: [
360
356
  {
361
357
  styles: {
362
- hide_secondary_level_menu: true,
358
+ show_secondary_level_menu: false,
363
359
  },
364
360
  },
365
361
  ],
@@ -370,16 +366,5 @@ describe("navigation", () => {
370
366
 
371
367
  expect(navBarVisible).toBe(true);
372
368
  });
373
-
374
- it("returns true otherwise", () => {
375
- const navBarVisible = isNavBarVisible(
376
- "",
377
- { navigations: [] } as any,
378
- true,
379
- true
380
- );
381
-
382
- expect(navBarVisible).toBe(true);
383
- });
384
369
  });
385
370
  });
@@ -0,0 +1,10 @@
1
+ import { platformSelect } from "../../reactUtils";
2
+
3
+ const TAB_BAR_HEIGHT_IOS = 49;
4
+ const TAB_BAR_HEIGHT_ANDROID = 56;
5
+
6
+ export const getTabBarHeight = () =>
7
+ platformSelect({
8
+ ios: TAB_BAR_HEIGHT_IOS,
9
+ android: TAB_BAR_HEIGHT_ANDROID,
10
+ }) as number;
@@ -1,9 +1,5 @@
1
- /* eslint-disable @typescript-eslint/no-use-before-define */
2
- /* eslint max-len: off */
3
-
4
- import React, { useContext, useEffect, useMemo } from "react";
5
- import { BackHandler, InteractionManager, NativeModules } from "react-native";
6
- import { useSafeAreaInsets } from "react-native-safe-area-context";
1
+ import { useContext, useEffect, useMemo, useRef } from "react";
2
+ import { BackHandler } from "react-native";
7
3
 
8
4
  import {
9
5
  useContentTypes,
@@ -11,34 +7,38 @@ import {
11
7
  } from "@applicaster/zapp-react-native-redux/hooks";
12
8
  import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
13
9
 
14
- import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
15
- import {
16
- LONG_KEY_PRESS_TIMEOUT,
17
- QUICK_BRICK_NAVBAR,
18
- QUICK_BRICK_CONTENT,
19
- } from "@applicaster/quick-brick-core/const";
20
- import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
10
+ import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
21
11
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
22
- import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
23
12
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
24
13
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
25
- import {
26
- getNavigationProps,
27
- getRiverFromRoute,
28
- getTargetRoute,
29
- } from "../../navigationUtils";
30
- import { platformSelect } from "../../reactUtils";
14
+ import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
31
15
  import { useConnectionInfo } from "../connection";
32
- import { getTargetScreenData } from "../screen/useTargetScreenData";
33
16
 
34
- import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
17
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
35
18
  import { useNavbarState } from "../screen";
36
- import { useNavigation } from "./useNavigation";
37
- import { useModalStore } from "../../modalState";
38
- import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
39
19
 
40
20
  export { useNavigation } from "./useNavigation";
41
21
 
22
+ export { useRoute } from "./useRoute";
23
+
24
+ export { usePathname } from "./usePathname";
25
+
26
+ export { useNavigationPluginData } from "./useNavigationPluginData";
27
+
28
+ export { useNavigationType } from "./useNavigationType";
29
+
30
+ export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
31
+
32
+ export { useIsScreenActive } from "./useIsScreenActive";
33
+
34
+ export { useProfilerLogging } from "./useProfilerLogging";
35
+
36
+ export {
37
+ useUniqueRouteSuffix,
38
+ useNavbarId,
39
+ useContentId,
40
+ } from "./useUniqueRouteSuffix";
41
+
42
42
  /**
43
43
  * This function helps to decide wether the navbar should be presented on the screen
44
44
  * based on route and / or screen Data
@@ -108,11 +108,13 @@ export function isNavBarVisible(
108
108
  return false;
109
109
  }
110
110
 
111
- const hideSecondaryLevel = screenData?.navigations?.some(
112
- (navigation) => navigation.styles?.hide_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
- if (canGoBack && hideSecondaryLevel) {
117
+ if (canGoBack && !showSecondaryLevel) {
116
118
  return false;
117
119
  }
118
120
 
@@ -123,12 +125,8 @@ export function isNavBarVisible(
123
125
  return true;
124
126
  }
125
127
 
126
- const { ProfilerBridge } = NativeModules;
127
-
128
- export const usePathname = () => React.useContext(PathnameContext);
129
-
130
128
  export const useBackHandler = (cb: () => boolean) => {
131
- React.useEffect(() => {
129
+ useEffect(() => {
132
130
  BackHandler.addEventListener("hardwareBackPress", cb);
133
131
 
134
132
  return () => {
@@ -137,88 +135,6 @@ export const useBackHandler = (cb: () => boolean) => {
137
135
  }, [cb]);
138
136
  };
139
137
 
140
- // starts with modal/
141
- const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
142
-
143
- const isVideoModalPathname = (pathname: string) =>
144
- /^video-modal\//.test(pathname);
145
-
146
- const isHookModalPathname = (pathname: string) =>
147
- /^hooks-modal\//.test(pathname);
148
-
149
- const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
150
-
151
- type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
152
-
153
- export const useRoute = (): {
154
- screenData: VariousScreenData;
155
- pathname: string;
156
- } => {
157
- const pathname = usePathname() || "";
158
- const navigator = useNavigation();
159
- const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
160
-
161
- const { plugins, contentTypes, rivers } = usePickFromState([
162
- "plugins",
163
- "rivers",
164
- "contentTypes",
165
- ]);
166
-
167
- const { modalState } = useModalStore();
168
- const hookModalState = useZappHooksModalState();
169
-
170
- const modalScreenData = modalState.screen;
171
-
172
- const hookModalScreenData = hookModalState.state.screenData?.payload;
173
-
174
- const videoModalScreenData =
175
- navigator.videoModalState?.item &&
176
- legacyScreenData(
177
- {
178
- entry: navigator.videoModalState?.item as ZappEntry,
179
- screen: getTargetScreenData(
180
- navigator.videoModalState?.item as ZappEntry,
181
- rivers,
182
- contentTypes
183
- ),
184
- },
185
- plugins
186
- );
187
-
188
- // There are 4 route scenarios
189
- // For regular screens take date from navigator stack.
190
- // is path is model grab screenData from modal state
191
- // if path is video modal grab screenData from video state
192
- // if path is hook modal grab screenData from hook state
193
- // if path is hook grab screenData from screenData
194
-
195
- if (isModalPathname(pathname)) {
196
- const screenData = modalScreenData ?? ({} as ZappEntry);
197
-
198
- return { screenData, pathname };
199
- }
200
-
201
- if (isVideoModalPathname(pathname)) {
202
- const screenData = videoModalScreenData as LegacyNavigationScreenData;
203
-
204
- return { screenData, pathname };
205
- }
206
-
207
- if (isHookModalPathname(pathname)) {
208
- const screenData = hookModalScreenData;
209
-
210
- return { screenData, pathname };
211
- }
212
-
213
- if (isHookPathname(pathname)) {
214
- return { screenData: screenDataContext, pathname };
215
- }
216
-
217
- const screenData = screenDataContext;
218
-
219
- return { screenData, pathname };
220
- };
221
-
222
138
  type Callbacks = Partial<{
223
139
  handleHookPresent: ({
224
140
  route,
@@ -244,7 +160,7 @@ export const useZappHooksForEntry = (
244
160
  setIsHooksExecutionInProgress,
245
161
  setIsPresentingFullScreen,
246
162
  setIsRunningInBackground,
247
- }: HookModalContextT = React.useContext(ZappHookModalContext.ReactContext);
163
+ }: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
248
164
 
249
165
  const {
250
166
  appData: { layoutVersion },
@@ -342,50 +258,10 @@ export const useZappHooksForEntry = (
342
258
  }, [entry.id]);
343
259
  };
344
260
 
345
- export enum MenuTypes {
346
- drawer = "DRAWER",
347
- bottomTabBar = "BOTTOM_TAB_BAR",
348
- }
349
-
350
- export const useNavigationPluginData = (): ZappNavigation | undefined => {
351
- const {
352
- screenData: useRouteScreenData,
353
- }: { screenData: QuickBrickNavigationData | null } = useRoute();
354
-
355
- const navigations = useRouteScreenData?.targetScreen
356
- ? (useRouteScreenData.targetScreen as ZappRiver).navigations
357
- : (useRouteScreenData as ZappRiver).navigations;
358
-
359
- const navigationMenu = navigations?.find((nav) => nav.category === "menu");
360
-
361
- return navigationMenu;
362
- };
363
-
364
- export const useNavigationType = (): MenuTypes => {
365
- const navigationMenu = useNavigationPluginData();
366
-
367
- return !navigationMenu ||
368
- navigationMenu.navigation_type === "quick_brick_side_menu"
369
- ? MenuTypes.drawer
370
- : MenuTypes.bottomTabBar;
371
- };
372
-
373
- export const useProfilerLogging = () => {
374
- const logTimestamp = (data: string) =>
375
- InteractionManager.runAfterInteractions(() => {
376
- if (ProfilerBridge && data) {
377
- ProfilerBridge.updateTimer("navigation", data, Date.now());
378
- }
379
- });
380
-
381
- return logTimestamp;
382
- };
383
-
384
261
  export const useRunIfLongPress = (
385
262
  options = { timeout: LONG_KEY_PRESS_TIMEOUT }
386
263
  ) => {
387
- const pressTimeout =
388
- React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
264
+ const pressTimeout = useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
389
265
 
390
266
  const resetTimeout = () => {
391
267
  clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
@@ -414,81 +290,3 @@ export const useIsNavBarVisible = (): boolean => {
414
290
 
415
291
  return useMemo(() => visible, [visible]);
416
292
  };
417
-
418
- const useGetNavBarTopBorderWidth = (): number => {
419
- const navigator = useNavigation();
420
-
421
- const navProps = getNavigationProps({
422
- navigator,
423
- title: "",
424
- category: "menu",
425
- });
426
-
427
- return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
428
- };
429
-
430
- const TAB_BAR_HEIGHT_IOS = 49;
431
- const TAB_BAR_HEIGHT_ANDROID = 56;
432
-
433
- const useGetTabBarHeight = () =>
434
- platformSelect({
435
- ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
436
- android: TAB_BAR_HEIGHT_ANDROID,
437
- }) as number;
438
-
439
- export const useGetBottomTabBarHeight = (): number => {
440
- const topBorderWidth = useGetNavBarTopBorderWidth();
441
- const tabBarHeight = useGetTabBarHeight();
442
-
443
- const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
444
-
445
- return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
446
- };
447
-
448
- // If current screen is active/focused (visible to the user)
449
- export const useIsScreenActive = () => {
450
- const pathname = usePathname();
451
- const { currentRoute, videoModalState } = useNavigation();
452
-
453
- if (
454
- videoModalState.visible &&
455
- ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
456
- ) {
457
- return false;
458
- }
459
-
460
- return pathname === currentRoute;
461
- };
462
-
463
- type Return = (prefix: string) => string;
464
-
465
- export const useUniqueRouteSuffix = (): Return => {
466
- const pathname = usePathname();
467
- const { currentRoute } = useNavigation();
468
-
469
- const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
470
-
471
- const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
472
- if (isWeb()) {
473
- // we should use extended route prefix only on Web, where we have stack-navigator
474
- return `${prefix}___${suffix}`;
475
- }
476
-
477
- // for other platforms use previous version
478
- return prefix;
479
- }, []);
480
-
481
- return withUniqueRouteSuffix;
482
- };
483
-
484
- export const useNavbarId = () => {
485
- const withUniqueRouteSuffix = useUniqueRouteSuffix();
486
-
487
- return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
488
- };
489
-
490
- export const useContentId = () => {
491
- const withUniqueRouteSuffix = useUniqueRouteSuffix();
492
-
493
- return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
494
- };
@@ -0,0 +1,19 @@
1
+ import { useGetNavBarTopBorderWidth } from "./useGetNavBarTopBorderWidth";
2
+ import { getTabBarHeight } from "./getTabBarHeight";
3
+ import { useNavigation } from "./useNavigation";
4
+ import { MenuTypes, useNavigationType } from "./useNavigationType";
5
+ import { useNavigationPluginData } from "./useNavigationPluginData";
6
+
7
+ export const useGetBottomTabBarHeight = (): number => {
8
+ const { activeRiver } = useNavigation();
9
+
10
+ const navigationPluginData = useNavigationPluginData(activeRiver);
11
+ const navigationType = useNavigationType(navigationPluginData);
12
+
13
+ const topBorderWidth = useGetNavBarTopBorderWidth();
14
+ const tabBarHeight = getTabBarHeight();
15
+
16
+ const isBottomBarNavigation = navigationType === MenuTypes.bottomTabBar;
17
+
18
+ return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
19
+ };
@@ -0,0 +1,14 @@
1
+ import { getNavigationProps } from "../../navigationUtils";
2
+ import { useNavigation } from "./useNavigation";
3
+
4
+ export const useGetNavBarTopBorderWidth = (): number => {
5
+ const navigator = useNavigation();
6
+
7
+ const navProps = getNavigationProps({
8
+ navigator,
9
+ title: "",
10
+ category: "menu",
11
+ });
12
+
13
+ return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
14
+ };
@@ -0,0 +1,17 @@
1
+ import { useNavigation } from "./useNavigation";
2
+ import { usePathname } from "./usePathname";
3
+
4
+ // If current screen is active/focused (visible to the user)
5
+ export const useIsScreenActive = () => {
6
+ const pathname = usePathname();
7
+ const { currentRoute, videoModalState } = useNavigation();
8
+
9
+ if (
10
+ videoModalState.visible &&
11
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
12
+ ) {
13
+ return false;
14
+ }
15
+
16
+ return pathname === currentRoute;
17
+ };
@@ -0,0 +1,19 @@
1
+ import { useRoute } from "./useRoute";
2
+
3
+ export const useNavigationPluginData = (
4
+ screenData?: LegacyNavigationScreenData | null
5
+ ): ZappNavigation | undefined => {
6
+ const {
7
+ screenData: useRouteScreenData,
8
+ }: { screenData: QuickBrickNavigationData | null } = useRoute();
9
+
10
+ const activeScreenData = screenData ?? useRouteScreenData;
11
+
12
+ const navigations = activeScreenData?.targetScreen
13
+ ? (activeScreenData.targetScreen as ZappRiver).navigations
14
+ : (activeScreenData as ZappRiver).navigations;
15
+
16
+ const navigationMenu = navigations?.find((nav) => nav.category === "menu");
17
+
18
+ return navigationMenu;
19
+ };
@@ -0,0 +1,17 @@
1
+ import { useNavigationPluginData } from "./useNavigationPluginData";
2
+
3
+ export enum MenuTypes {
4
+ drawer = "DRAWER",
5
+ bottomTabBar = "BOTTOM_TAB_BAR",
6
+ }
7
+
8
+ export const useNavigationType = (navigation?: ZappNavigation): MenuTypes => {
9
+ const navigationPluginData = useNavigationPluginData();
10
+
11
+ const navigationMenu = navigation ?? navigationPluginData;
12
+
13
+ return !navigationMenu ||
14
+ navigationMenu.navigation_type === "quick_brick_side_menu"
15
+ ? MenuTypes.drawer
16
+ : MenuTypes.bottomTabBar;
17
+ };
@@ -0,0 +1,4 @@
1
+ import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
2
+ import React from "react";
3
+
4
+ export const usePathname = () => React.useContext(PathnameContext);
@@ -0,0 +1,15 @@
1
+ import { useCallback } from "react";
2
+ import { InteractionManager, NativeModules } from "react-native";
3
+
4
+ const { ProfilerBridge } = NativeModules;
5
+
6
+ export const useProfilerLogging = () =>
7
+ useCallback(
8
+ (data: string) =>
9
+ InteractionManager.runAfterInteractions(() => {
10
+ if (ProfilerBridge && data) {
11
+ ProfilerBridge.updateTimer("navigation", data, Date.now());
12
+ }
13
+ }),
14
+ []
15
+ );
@@ -0,0 +1,98 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+ /* eslint max-len: off */
3
+
4
+ import { useContext } from "react";
5
+
6
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
+
8
+ import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
9
+
10
+ import { getTargetScreenData } from "../screen/useTargetScreenData";
11
+ import { useHookModalScreenData } from "../hookModal/hooks/useHookModalScreenData";
12
+
13
+ import { useNavigation } from "./useNavigation";
14
+ import { useModalStoreState } from "../../modalState";
15
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
16
+ import { usePathname } from "./usePathname";
17
+
18
+ // starts with modal/
19
+ const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
20
+
21
+ const isVideoModalPathname = (pathname: string) =>
22
+ /^video-modal\//.test(pathname);
23
+
24
+ const isHookModalPathname = (pathname: string) =>
25
+ /^hooks-modal\//.test(pathname);
26
+
27
+ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
28
+
29
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
30
+
31
+ export const useRoute = (): {
32
+ screenData: VariousScreenData;
33
+ pathname: string;
34
+ } => {
35
+ const pathname = usePathname() || "";
36
+ const navigator = useNavigation();
37
+
38
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
39
+
40
+ const { plugins, contentTypes, rivers } = usePickFromState([
41
+ "plugins",
42
+ "rivers",
43
+ "contentTypes",
44
+ ]);
45
+
46
+ const modalState = useModalStoreState();
47
+
48
+ const modalScreenData = modalState.screen;
49
+
50
+ const hookModalScreenData = useHookModalScreenData();
51
+
52
+ const videoModalScreenData =
53
+ navigator?.videoModalState?.item &&
54
+ legacyScreenData(
55
+ {
56
+ entry: navigator.videoModalState?.item as ZappEntry,
57
+ screen: getTargetScreenData(
58
+ navigator.videoModalState?.item as ZappEntry,
59
+ rivers,
60
+ contentTypes
61
+ ),
62
+ },
63
+ plugins
64
+ );
65
+
66
+ // There are 4 route scenarios
67
+ // For regular screens take date from navigator stack.
68
+ // is path is model grab screenData from modal state
69
+ // if path is video modal grab screenData from video state
70
+ // if path is hook modal grab screenData from hook state
71
+ // if path is hook grab screenData from screenData
72
+
73
+ if (isModalPathname(pathname)) {
74
+ const screenData = modalScreenData ?? ({} as ZappEntry);
75
+
76
+ return { screenData, pathname };
77
+ }
78
+
79
+ if (isVideoModalPathname(pathname)) {
80
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
81
+
82
+ return { screenData, pathname };
83
+ }
84
+
85
+ if (isHookModalPathname(pathname)) {
86
+ const screenData = hookModalScreenData;
87
+
88
+ return { screenData, pathname };
89
+ }
90
+
91
+ if (isHookPathname(pathname)) {
92
+ return { screenData: screenDataContext, pathname };
93
+ }
94
+
95
+ const screenData = screenDataContext;
96
+
97
+ return { screenData, pathname };
98
+ };
@@ -0,0 +1,41 @@
1
+ import React from "react";
2
+ import { isWeb } from "../../reactUtils";
3
+ import { useNavigation } from "./useNavigation";
4
+ import { usePathname } from "./usePathname";
5
+ import {
6
+ QUICK_BRICK_CONTENT,
7
+ QUICK_BRICK_NAVBAR,
8
+ } from "@applicaster/quick-brick-core/const";
9
+
10
+ type Return = (prefix: string) => string;
11
+
12
+ export const useUniqueRouteSuffix = (): Return => {
13
+ const pathname = usePathname();
14
+ const { currentRoute } = useNavigation();
15
+
16
+ const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
17
+
18
+ const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
19
+ if (isWeb()) {
20
+ // we should use extended route prefix only on Web, where we have stack-navigator
21
+ return `${prefix}___${suffix}`;
22
+ }
23
+
24
+ // for other platforms use previous version
25
+ return prefix;
26
+ }, []);
27
+
28
+ return withUniqueRouteSuffix;
29
+ };
30
+
31
+ export const useNavbarId = () => {
32
+ const withUniqueRouteSuffix = useUniqueRouteSuffix();
33
+
34
+ return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
35
+ };
36
+
37
+ export const useContentId = () => {
38
+ const withUniqueRouteSuffix = useUniqueRouteSuffix();
39
+
40
+ return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
41
+ };