@applicaster/zapp-react-native-utils 13.0.0-rc.7 → 13.0.0-rc.70

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 (148) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +74 -9
  4. package/alertUtils/alert.ts +148 -0
  5. package/alertUtils/index.ts +1 -148
  6. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  7. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  8. package/analyticsUtils/currentScreenProperities.ts +6 -4
  9. package/analyticsUtils/helpers/hooks.ts +1 -1
  10. package/appUtils/HooksManager/{Hook.js → Hook.ts} +35 -23
  11. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
  12. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
  13. package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
  14. package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
  15. package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
  16. package/appUtils/HooksManager/{index.js → index.ts} +122 -113
  17. package/appUtils/HooksManager/types.ts +119 -0
  18. package/appUtils/RiverFocusManager/index.js +17 -12
  19. package/appUtils/accessibilityManager/index.ts +42 -1
  20. package/appUtils/contextKeysManager/contextResolver.ts +77 -0
  21. package/appUtils/contextKeysManager/index.ts +2 -2
  22. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  23. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -6
  24. package/appUtils/focusManager/index.ts +100 -74
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
  26. package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
  27. package/appUtils/focusManager/utils/enums.ts +4 -0
  28. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  29. package/appUtils/{index.js → index.ts} +1 -1
  30. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  31. package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
  32. package/appUtils/keyCodes/{index.js → index.ts} +13 -7
  33. package/appUtils/keyCodes/keys/index.ts +3 -0
  34. package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
  35. package/appUtils/keyCodes/keys/keys.android.ts +18 -0
  36. package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
  37. package/appUtils/keyCodes/keys/keys.ts +15 -0
  38. package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +4 -0
  39. package/appUtils/keyCodes/keysByPlatform.ts +8 -0
  40. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  41. package/appUtils/orientationHelper.ts +11 -13
  42. package/appUtils/platform/const.ts +14 -0
  43. package/appUtils/platform/platformUtils.ts +47 -18
  44. package/appUtils/playerManager/index.ts +7 -3
  45. package/appUtils/playerManager/player.ts +23 -7
  46. package/appUtils/playerManager/playerNative.ts +6 -1
  47. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  48. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  49. package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
  50. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  51. package/equalUtils/index.ts +49 -30
  52. package/focusManager/FocusManager.ts +11 -1
  53. package/focusManager/index.ts +41 -4
  54. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  55. package/functionUtils/index.ts +36 -19
  56. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  57. package/idleUtils/index.ts +1 -1
  58. package/idleUtils/withTimeout.ts +15 -2
  59. package/logger/const.ts +9 -67
  60. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  61. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  62. package/manifestUtils/fonts/index.js +5 -6
  63. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  64. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  65. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  66. package/modalState/index.ts +1 -5
  67. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
  68. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  69. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  70. package/navigationUtils/index.ts +17 -8
  71. package/numberUtils/index.ts +7 -5
  72. package/package.json +5 -9
  73. package/playerUtils/configurationGenerator.ts +8 -0
  74. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  75. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  76. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  77. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  78. package/reactHooks/cell-click/index.ts +7 -1
  79. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  80. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  81. package/reactHooks/feed/useFeedLoader.tsx +1 -1
  82. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  83. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  84. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  85. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  86. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  87. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  88. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  89. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  90. package/reactHooks/navigation/index.ts +38 -239
  91. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
  92. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  93. package/reactHooks/navigation/useGetTabBarHeight.ts +10 -0
  94. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  95. package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
  96. package/reactHooks/navigation/useNavigationType.ts +15 -0
  97. package/reactHooks/navigation/usePathname.ts +4 -0
  98. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  99. package/reactHooks/navigation/useRoute.ts +100 -0
  100. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  101. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  102. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  103. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  104. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  105. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  106. package/reactHooks/player/const.ts +0 -4
  107. package/reactHooks/player/index.ts +0 -6
  108. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  109. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  110. package/reactHooks/usePluginConfiguration.ts +1 -1
  111. package/reactHooks/useSubscriberFor.ts +4 -3
  112. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  113. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  114. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  115. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  116. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  117. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  118. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  119. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  120. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  121. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  122. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  123. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  124. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  125. package/reactUtils/createContext/helpers.ts +6 -1
  126. package/reactUtils/createContext/index.ts +11 -25
  127. package/reactUtils/index.ts +0 -25
  128. package/screenState/index.ts +24 -10
  129. package/services/js2native.ts +673 -0
  130. package/testUtils/index.tsx +0 -10
  131. package/theme/__mocks__/index.ts +4 -0
  132. package/theme/index.ts +1 -1
  133. package/time/BackgroundTimer.ts +55 -0
  134. package/time/Timer.ts +9 -6
  135. package/types.ts +1 -0
  136. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  137. package/appUtils/keyCodes/keys.ios.js +0 -46
  138. package/reactHooks/player/useAutoSeek.tsx +0 -87
  139. package/reactHooks/player/useSeek.tsx +0 -66
  140. package/reactHooks/player/useTapSeek.tsx +0 -58
  141. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  142. /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
  143. /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
  144. /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
  145. /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
  146. /package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +0 -0
  147. /package/domUtils/{logger.js → logger.ts} +0 -0
  148. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -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,11 @@ 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
111
+ const showSecondaryLevel = screenData?.navigations?.some(
112
+ (navigation) => navigation.styles?.show_secondary_level_menu
113
113
  );
114
114
 
115
- if (canGoBack && hideSecondaryLevel) {
115
+ if (canGoBack && !showSecondaryLevel) {
116
116
  return false;
117
117
  }
118
118
 
@@ -123,12 +123,8 @@ export function isNavBarVisible(
123
123
  return true;
124
124
  }
125
125
 
126
- const { ProfilerBridge } = NativeModules;
127
-
128
- export const usePathname = () => React.useContext(PathnameContext);
129
-
130
126
  export const useBackHandler = (cb: () => boolean) => {
131
- React.useEffect(() => {
127
+ useEffect(() => {
132
128
  BackHandler.addEventListener("hardwareBackPress", cb);
133
129
 
134
130
  return () => {
@@ -137,88 +133,6 @@ export const useBackHandler = (cb: () => boolean) => {
137
133
  }, [cb]);
138
134
  };
139
135
 
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
136
  type Callbacks = Partial<{
223
137
  handleHookPresent: ({
224
138
  route,
@@ -244,7 +158,7 @@ export const useZappHooksForEntry = (
244
158
  setIsHooksExecutionInProgress,
245
159
  setIsPresentingFullScreen,
246
160
  setIsRunningInBackground,
247
- }: HookModalContextT = React.useContext(ZappHookModalContext.ReactContext);
161
+ }: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
248
162
 
249
163
  const {
250
164
  appData: { layoutVersion },
@@ -320,16 +234,19 @@ export const useZappHooksForEntry = (
320
234
  callbacks?.handleHookComplete?.(props);
321
235
  };
322
236
 
323
- const hookManager = HooksManager(hooksOptions)
237
+ const hookManager = HooksManager(hooksOptions);
238
+
239
+ hookManager.subscriber
324
240
  .on(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
325
241
  .on(HOOKS_EVENTS.ERROR, handleHookError)
326
242
  .on(HOOKS_EVENTS.CANCEL, handleHookCancel)
327
243
  .on(HOOKS_EVENTS.START_BACKGROUND_HOOK, handleBackgroundHook)
328
- .on(HOOKS_EVENTS.COMPLETE, handleHookComplete)
329
- .handleHooks(entry);
244
+ .on(HOOKS_EVENTS.COMPLETE, handleHookComplete);
245
+
246
+ hookManager.handleHooks(entry);
330
247
 
331
248
  return () => {
332
- hookManager
249
+ hookManager.subscriber
333
250
  .removeHandler(HOOKS_EVENTS.PRESENT_SCREEN_HOOK, handleHookPresent)
334
251
  .removeHandler(HOOKS_EVENTS.ERROR, handleHookError)
335
252
  .removeHandler(HOOKS_EVENTS.CANCEL, handleHookCancel)
@@ -339,50 +256,10 @@ export const useZappHooksForEntry = (
339
256
  }, [entry.id]);
340
257
  };
341
258
 
342
- export enum MenuTypes {
343
- drawer = "DRAWER",
344
- bottomTabBar = "BOTTOM_TAB_BAR",
345
- }
346
-
347
- export const useNavigationPluginData = (): ZappNavigation | undefined => {
348
- const {
349
- screenData: useRouteScreenData,
350
- }: { screenData: QuickBrickNavigationData | null } = useRoute();
351
-
352
- const navigations = useRouteScreenData?.targetScreen
353
- ? (useRouteScreenData.targetScreen as ZappRiver).navigations
354
- : (useRouteScreenData as ZappRiver).navigations;
355
-
356
- const navigationMenu = navigations?.find((nav) => nav.category === "menu");
357
-
358
- return navigationMenu;
359
- };
360
-
361
- export const useNavigationType = (): MenuTypes => {
362
- const navigationMenu = useNavigationPluginData();
363
-
364
- return !navigationMenu ||
365
- navigationMenu.navigation_type === "quick_brick_side_menu"
366
- ? MenuTypes.drawer
367
- : MenuTypes.bottomTabBar;
368
- };
369
-
370
- export const useProfilerLogging = () => {
371
- const logTimestamp = (data: string) =>
372
- InteractionManager.runAfterInteractions(() => {
373
- if (ProfilerBridge && data) {
374
- ProfilerBridge.updateTimer("navigation", data, Date.now());
375
- }
376
- });
377
-
378
- return logTimestamp;
379
- };
380
-
381
259
  export const useRunIfLongPress = (
382
260
  options = { timeout: LONG_KEY_PRESS_TIMEOUT }
383
261
  ) => {
384
- const pressTimeout =
385
- React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
262
+ const pressTimeout = useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
386
263
 
387
264
  const resetTimeout = () => {
388
265
  clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
@@ -411,81 +288,3 @@ export const useIsNavBarVisible = (): boolean => {
411
288
 
412
289
  return useMemo(() => visible, [visible]);
413
290
  };
414
-
415
- const useGetNavBarTopBorderWidth = (): number => {
416
- const navigator = useNavigation();
417
-
418
- const navProps = getNavigationProps({
419
- navigator,
420
- title: "",
421
- category: "menu",
422
- });
423
-
424
- return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
425
- };
426
-
427
- const TAB_BAR_HEIGHT_IOS = 49;
428
- const TAB_BAR_HEIGHT_ANDROID = 56;
429
-
430
- const useGetTabBarHeight = () =>
431
- platformSelect({
432
- ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
433
- android: TAB_BAR_HEIGHT_ANDROID,
434
- }) as number;
435
-
436
- export const useGetBottomTabBarHeight = (): number => {
437
- const topBorderWidth = useGetNavBarTopBorderWidth();
438
- const tabBarHeight = useGetTabBarHeight();
439
-
440
- const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
441
-
442
- return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
443
- };
444
-
445
- // If current screen is active/focused (visible to the user)
446
- export const useIsScreenActive = () => {
447
- const pathname = usePathname();
448
- const { currentRoute, videoModalState } = useNavigation();
449
-
450
- if (
451
- videoModalState.visible &&
452
- ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
453
- ) {
454
- return false;
455
- }
456
-
457
- return pathname === currentRoute;
458
- };
459
-
460
- type Return = (prefix: string) => string;
461
-
462
- export const useUniqueRouteSuffix = (): Return => {
463
- const pathname = usePathname();
464
- const { currentRoute } = useNavigation();
465
-
466
- const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
467
-
468
- const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
469
- if (isWeb()) {
470
- // we should use extended route prefix only on Web, where we have stack-navigator
471
- return `${prefix}___${suffix}`;
472
- }
473
-
474
- // for other platforms use previous version
475
- return prefix;
476
- }, []);
477
-
478
- return withUniqueRouteSuffix;
479
- };
480
-
481
- export const useNavbarId = () => {
482
- const withUniqueRouteSuffix = useUniqueRouteSuffix();
483
-
484
- return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
485
- };
486
-
487
- export const useContentId = () => {
488
- const withUniqueRouteSuffix = useUniqueRouteSuffix();
489
-
490
- return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
491
- };
@@ -0,0 +1,12 @@
1
+ import { useGetNavBarTopBorderWidth } from "./useGetNavBarTopBorderWidth";
2
+ import { useGetTabBarHeight } from "./useGetTabBarHeight";
3
+ import { MenuTypes, useNavigationType } from "./useNavigationType";
4
+
5
+ export const useGetBottomTabBarHeight = (): number => {
6
+ const topBorderWidth = useGetNavBarTopBorderWidth();
7
+ const tabBarHeight = useGetTabBarHeight();
8
+
9
+ const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
10
+
11
+ return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
12
+ };
@@ -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,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 useGetTabBarHeight = () =>
7
+ platformSelect({
8
+ ios: TAB_BAR_HEIGHT_IOS,
9
+ android: TAB_BAR_HEIGHT_ANDROID,
10
+ }) as number;
@@ -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,15 @@
1
+ import { useRoute } from "./useRoute";
2
+
3
+ export const useNavigationPluginData = (): ZappNavigation | undefined => {
4
+ const {
5
+ screenData: useRouteScreenData,
6
+ }: { screenData: QuickBrickNavigationData | null } = useRoute();
7
+
8
+ const navigations = useRouteScreenData?.targetScreen
9
+ ? (useRouteScreenData.targetScreen as ZappRiver).navigations
10
+ : (useRouteScreenData as ZappRiver).navigations;
11
+
12
+ const navigationMenu = navigations?.find((nav) => nav.category === "menu");
13
+
14
+ return navigationMenu;
15
+ };
@@ -0,0 +1,15 @@
1
+ import { useNavigationPluginData } from "./useNavigationPluginData";
2
+
3
+ export enum MenuTypes {
4
+ drawer = "DRAWER",
5
+ bottomTabBar = "BOTTOM_TAB_BAR",
6
+ }
7
+
8
+ export const useNavigationType = (): MenuTypes => {
9
+ const navigationMenu = useNavigationPluginData();
10
+
11
+ return !navigationMenu ||
12
+ navigationMenu.navigation_type === "quick_brick_side_menu"
13
+ ? MenuTypes.drawer
14
+ : MenuTypes.bottomTabBar;
15
+ };
@@ -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,100 @@
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 { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
11
+
12
+ import { getTargetScreenData } from "../screen/useTargetScreenData";
13
+
14
+ import { useNavigation } from "./useNavigation";
15
+ import { useModalStore } from "../../modalState";
16
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
17
+ import { usePathname } from "./usePathname";
18
+
19
+ // starts with modal/
20
+ const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
21
+
22
+ const isVideoModalPathname = (pathname: string) =>
23
+ /^video-modal\//.test(pathname);
24
+
25
+ const isHookModalPathname = (pathname: string) =>
26
+ /^hooks-modal\//.test(pathname);
27
+
28
+ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
29
+
30
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
31
+
32
+ export const useRoute = (): {
33
+ screenData: VariousScreenData;
34
+ pathname: string;
35
+ } => {
36
+ const pathname = usePathname() || "";
37
+ const navigator = useNavigation();
38
+
39
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
40
+
41
+ const { plugins, contentTypes, rivers } = usePickFromState([
42
+ "plugins",
43
+ "rivers",
44
+ "contentTypes",
45
+ ]);
46
+
47
+ const { modalState } = useModalStore();
48
+ const hookModalState = useZappHooksModalState();
49
+
50
+ const modalScreenData = modalState.screen;
51
+
52
+ const hookModalScreenData = hookModalState.state.screenData?.payload;
53
+
54
+ const videoModalScreenData =
55
+ navigator?.videoModalState?.item &&
56
+ legacyScreenData(
57
+ {
58
+ entry: navigator.videoModalState?.item as ZappEntry,
59
+ screen: getTargetScreenData(
60
+ navigator.videoModalState?.item as ZappEntry,
61
+ rivers,
62
+ contentTypes
63
+ ),
64
+ },
65
+ plugins
66
+ );
67
+
68
+ // There are 4 route scenarios
69
+ // For regular screens take date from navigator stack.
70
+ // is path is model grab screenData from modal state
71
+ // if path is video modal grab screenData from video state
72
+ // if path is hook modal grab screenData from hook state
73
+ // if path is hook grab screenData from screenData
74
+
75
+ if (isModalPathname(pathname)) {
76
+ const screenData = modalScreenData ?? ({} as ZappEntry);
77
+
78
+ return { screenData, pathname };
79
+ }
80
+
81
+ if (isVideoModalPathname(pathname)) {
82
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
83
+
84
+ return { screenData, pathname };
85
+ }
86
+
87
+ if (isHookModalPathname(pathname)) {
88
+ const screenData = hookModalScreenData;
89
+
90
+ return { screenData, pathname };
91
+ }
92
+
93
+ if (isHookPathname(pathname)) {
94
+ return { screenData: screenDataContext, pathname };
95
+ }
96
+
97
+ const screenData = screenDataContext;
98
+
99
+ return { screenData, pathname };
100
+ };
@@ -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
+ };
@@ -0,0 +1,32 @@
1
+ import { MAX_SEEK_TIME, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
2
+
3
+ export interface ISeekControllerDelegate {
4
+ handleDelayedSeek(offset: number): void;
5
+ handleSeek(offset: number): void;
6
+ handleSeekComplete(): void;
7
+ handlePlayerPause(): void;
8
+ }
9
+
10
+ export interface ISeekController {
11
+ title: string;
12
+ onStartSeek(seekType: SEEK_TYPE): void;
13
+ onSeekEnd(): void;
14
+ reset(): void;
15
+ }
16
+
17
+ export class SeekIncrementalBaseStrategy {
18
+ private skipMultiplier = 1;
19
+
20
+ getSkipTime = () =>
21
+ Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * this.skipMultiplier);
22
+
23
+ increment = () => {
24
+ this.skipMultiplier++;
25
+ };
26
+
27
+ getSkipMultiplier = () => this.skipMultiplier;
28
+
29
+ reset = () => {
30
+ this.skipMultiplier = 1;
31
+ };
32
+ }