@applicaster/zapp-react-native-utils 15.0.0-alpha.9667030680 → 15.0.0-alpha.9980835537

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 (177) hide show
  1. package/README.md +0 -6
  2. package/actionUtils/index.ts +7 -0
  3. package/actionsExecutor/ActionExecutorContext.tsx +86 -12
  4. package/actionsExecutor/feedDecorator.ts +6 -6
  5. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  6. package/adsUtils/index.ts +2 -2
  7. package/analyticsUtils/README.md +1 -1
  8. package/analyticsUtils/analyticsMapper.ts +10 -2
  9. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  10. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  11. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  12. package/appUtils/HooksManager/index.ts +45 -10
  13. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  14. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  15. package/appUtils/accessibilityManager/const.ts +4 -0
  16. package/appUtils/accessibilityManager/hooks.ts +20 -13
  17. package/appUtils/accessibilityManager/index.ts +28 -1
  18. package/appUtils/accessibilityManager/utils.ts +59 -8
  19. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  20. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  21. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  22. package/appUtils/contextKeysManager/index.ts +65 -10
  23. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  24. package/appUtils/focusManager/index.ios.ts +43 -4
  25. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  26. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  27. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  28. package/appUtils/focusManagerAux/utils/index.ts +13 -7
  29. package/appUtils/focusManagerAux/utils/utils.ios.ts +202 -3
  30. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  31. package/appUtils/localizationsHelper.ts +4 -0
  32. package/appUtils/orientationHelper.ts +2 -4
  33. package/appUtils/platform/platformUtils.ts +115 -16
  34. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  35. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  36. package/appUtils/playerManager/index.ts +9 -0
  37. package/appUtils/playerManager/player.ts +5 -1
  38. package/appUtils/playerManager/playerNative.ts +31 -17
  39. package/appUtils/playerManager/usePlayer.tsx +5 -3
  40. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  41. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  42. package/cellUtils/index.ts +12 -9
  43. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  44. package/cloudEventsUtils/index.ts +65 -1
  45. package/componentsUtils/index.ts +8 -0
  46. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  47. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  48. package/configurationUtils/index.ts +17 -11
  49. package/dateUtils/__tests__/dayjs.test.ts +327 -0
  50. package/dateUtils/index.ts +2 -0
  51. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  52. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  53. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  54. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  55. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  56. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  57. package/errorUtils/__tests__/invariant.test.ts +112 -0
  58. package/focusManager/aux/index.ts +1 -1
  59. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  60. package/headersUtils/index.ts +2 -1
  61. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  62. package/manifestUtils/_internals/index.js +33 -0
  63. package/manifestUtils/defaultManifestConfigurations/player.js +115 -11
  64. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  65. package/manifestUtils/fieldUtils/index.js +54 -0
  66. package/manifestUtils/index.js +2 -0
  67. package/manifestUtils/keys.js +249 -0
  68. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  69. package/manifestUtils/mobileAction/button/index.js +140 -0
  70. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  71. package/manifestUtils/mobileAction/container/index.js +73 -0
  72. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  73. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  74. package/manifestUtils/mobileAction/groups/index.js +80 -0
  75. package/manifestUtils/platformIsTV.js +13 -0
  76. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  77. package/manifestUtils/tvAction/container/index.js +1 -1
  78. package/navigationUtils/index.ts +15 -5
  79. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  80. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  81. package/numberUtils/index.ts +23 -1
  82. package/package.json +4 -4
  83. package/playerUtils/usePlayerTTS.ts +8 -3
  84. package/pluginUtils/index.ts +4 -0
  85. package/reactHooks/advertising/index.ts +2 -2
  86. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  87. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  88. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  89. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  90. package/reactHooks/casting/index.ts +1 -0
  91. package/reactHooks/casting/useIsCasting.tsx +57 -0
  92. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  93. package/reactHooks/cell-click/index.ts +2 -1
  94. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  95. package/reactHooks/connection/__tests__/index.test.js +1 -1
  96. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  97. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  98. package/reactHooks/device/useIsTablet.tsx +14 -19
  99. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  100. package/reactHooks/events/index.ts +20 -0
  101. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  102. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  103. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  104. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  105. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  106. package/reactHooks/feed/index.ts +0 -2
  107. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  108. package/reactHooks/feed/useInflatedUrl.ts +44 -18
  109. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  110. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  111. package/reactHooks/index.ts +2 -0
  112. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  113. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  114. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  115. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  116. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  117. package/reactHooks/navigation/index.ts +27 -11
  118. package/reactHooks/navigation/useRoute.ts +11 -7
  119. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  120. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  121. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  122. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  123. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  124. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  125. package/reactHooks/resolvers/useComponentResolver.ts +19 -3
  126. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  127. package/reactHooks/screen/__tests__/useCurrentScreenIsHook.test.ts +103 -0
  128. package/reactHooks/screen/__tests__/useCurrentScreenIsStartupHook.test.ts +94 -0
  129. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  130. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  131. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  132. package/reactHooks/screen/index.ts +4 -0
  133. package/reactHooks/screen/useCurrentScreenIsHook.ts +9 -0
  134. package/reactHooks/screen/useCurrentScreenIsStartupHook.ts +8 -0
  135. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  136. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  137. package/reactHooks/state/index.ts +2 -0
  138. package/reactHooks/state/useComponentScreenState.ts +45 -0
  139. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  140. package/reactHooks/state/useRivers.ts +1 -1
  141. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  142. package/reactHooks/usePluginConfiguration.ts +2 -2
  143. package/reactHooks/utils/__tests__/index.test.js +1 -1
  144. package/rectUtils/__tests__/index.test.ts +549 -0
  145. package/rectUtils/index.ts +2 -2
  146. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  147. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  148. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  149. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  150. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  151. package/screenPickerUtils/index.ts +5 -0
  152. package/screenState/__tests__/index.test.ts +1 -1
  153. package/screenUtils/index.ts +3 -0
  154. package/searchUtils/const.ts +7 -0
  155. package/searchUtils/index.ts +3 -0
  156. package/services/storageServiceSync.web.ts +1 -1
  157. package/stringUtils/index.ts +1 -1
  158. package/testUtils/index.tsx +30 -21
  159. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  160. package/time/__tests__/Timer.test.ts +236 -0
  161. package/typeGuards/__tests__/isString.test.ts +21 -0
  162. package/typeGuards/index.ts +4 -0
  163. package/utils/__tests__/clone.test.ts +158 -0
  164. package/utils/__tests__/mergeRight.test.ts +48 -0
  165. package/utils/__tests__/path.test.ts +7 -0
  166. package/utils/__tests__/selectors.test.ts +124 -0
  167. package/utils/clone.ts +7 -0
  168. package/utils/index.ts +15 -1
  169. package/utils/mergeRight.ts +5 -0
  170. package/utils/path.ts +6 -3
  171. package/utils/pathOr.ts +5 -1
  172. package/utils/selectors.ts +46 -0
  173. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +34 -11
  174. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  175. package/reactHooks/componentsMap/index.ts +0 -55
  176. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  177. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -1,21 +1,24 @@
1
- import { useContext, useEffect, useMemo, useRef } from "react";
1
+ import { useEffect, useMemo, useRef } from "react";
2
2
  import { BackHandler } from "react-native";
3
+ import { shallow } from "zustand/shallow";
3
4
 
4
5
  import {
5
6
  useContentTypes,
6
- usePickFromState,
7
+ usePlugins,
7
8
  } from "@applicaster/zapp-react-native-redux/hooks";
8
9
  import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
9
10
 
10
11
  import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
11
- import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
12
- import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
12
+ import { useZappHookModalStore } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
13
13
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
14
14
  import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
15
15
  import { useConnectionInfo } from "../connection";
16
16
 
17
17
  import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { pick } from "@applicaster/zapp-react-native-utils/utils";
18
19
  import { useNavbarState } from "../screen";
20
+ import { useRivers } from "../state";
21
+ import { useLayoutVersion } from "../layout";
19
22
 
20
23
  export { useNavigation } from "./useNavigation";
21
24
 
@@ -86,6 +89,10 @@ export function isNavBarVisible(
86
89
  if (route.startsWith("/hooks/")) {
87
90
  const module = screenData?.module;
88
91
 
92
+ if (module === undefined) {
93
+ return showNavBar;
94
+ }
95
+
89
96
  if (module?.presentFullScreen) {
90
97
  return false;
91
98
  }
@@ -162,13 +169,22 @@ export const useZappHooksForEntry = (
162
169
  setIsHooksExecutionInProgress,
163
170
  setIsPresentingFullScreen,
164
171
  setIsRunningInBackground,
165
- }: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
166
-
167
- const {
168
- appData: { layoutVersion },
169
- rivers,
170
- plugins,
171
- } = usePickFromState(["appData", "rivers", "plugins"]);
172
+ } = useZappHookModalStore(
173
+ (state) =>
174
+ pick(state, [
175
+ "setState",
176
+ "resetState",
177
+ "setIsHooksExecutionInProgress",
178
+ "setIsPresentingFullScreen",
179
+ "setIsRunningInBackground",
180
+ ]),
181
+ shallow
182
+ );
183
+
184
+ const plugins = usePlugins();
185
+ const rivers = useRivers();
186
+
187
+ const layoutVersion = useLayoutVersion();
172
188
 
173
189
  const contentTypes = useContentTypes();
174
190
 
@@ -3,7 +3,10 @@
3
3
 
4
4
  import { useContext } from "react";
5
5
 
6
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
6
+ import {
7
+ useContentTypes,
8
+ usePlugins,
9
+ } from "@applicaster/zapp-react-native-redux/hooks";
7
10
 
8
11
  import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
9
12
 
@@ -14,6 +17,7 @@ import { useNavigation } from "./useNavigation";
14
17
  import { useModalStoreState } from "../../modalState";
15
18
  import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
16
19
  import { usePathname } from "./usePathname";
20
+ import { useRivers } from "../state";
17
21
 
18
22
  // starts with modal/
19
23
  const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
@@ -42,17 +46,17 @@ export const useRoute = (
42
46
  ? legacyScreenData(screenContext)
43
47
  : screenContext;
44
48
 
45
- const { plugins, contentTypes, rivers } = usePickFromState([
46
- "plugins",
47
- "rivers",
48
- "contentTypes",
49
- ]);
49
+ const plugins = usePlugins();
50
+ const rivers = useRivers();
51
+ const contentTypes = useContentTypes();
50
52
 
51
53
  const modalState = useModalStoreState();
52
54
 
53
55
  const modalScreenData = modalState.screen;
54
56
 
55
- const hookModalScreenData = useHookModalScreenData();
57
+ const hookModalScreenData = useHookModalScreenData(
58
+ !isHookModalPathname(pathname)
59
+ );
56
60
 
57
61
  const videoModalScreenData =
58
62
  navigator?.videoModalState?.item &&
@@ -147,17 +147,34 @@ export class TVSeekController
147
147
 
148
148
  let targetPos = currentPos;
149
149
 
150
- if (this.currentSeekType === SEEK_TYPE.FORWARD) {
151
- targetPos = Math.min(
152
- currentPos + offset,
153
- this.playerController.getSeekableDuration()
154
- );
155
- } else if (this.currentSeekType === SEEK_TYPE.REWIND) {
156
- targetPos = Math.max(0, currentPos - offset);
150
+ const isLive = this.playerController.isLive();
151
+
152
+ if (isLive) {
153
+ if (this.currentSeekType === SEEK_TYPE.REWIND) {
154
+ targetPos = Math.min(
155
+ currentPos + offset,
156
+ this.playerController.getSeekableDuration()
157
+ );
158
+ } else if (this.currentSeekType === SEEK_TYPE.FORWARD) {
159
+ targetPos = Math.max(0, currentPos - offset);
160
+ } else {
161
+ log_warning(
162
+ `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
163
+ );
164
+ }
157
165
  } else {
158
- log_warning(
159
- `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
160
- );
166
+ if (this.currentSeekType === SEEK_TYPE.FORWARD) {
167
+ targetPos = Math.min(
168
+ currentPos + offset,
169
+ this.playerController.getSeekableDuration()
170
+ );
171
+ } else if (this.currentSeekType === SEEK_TYPE.REWIND) {
172
+ targetPos = Math.max(0, currentPos - offset);
173
+ } else {
174
+ log_warning(
175
+ `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
176
+ );
177
+ }
161
178
  }
162
179
 
163
180
  log_debug(
@@ -1,4 +1,4 @@
1
- import { act, renderHook } from "@testing-library/react-hooks";
1
+ import { act, renderHook } from "@testing-library/react-native";
2
2
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
3
 
4
4
  import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
3
  import { useTapSeek } from "../useTapSeek";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { cleanup, renderHook } from "@testing-library/react-hooks";
3
+ import { cleanup, renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { Provider } from "react-redux";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { renderHook, cleanup } from "@testing-library/react-hooks";
2
+ import { renderHook, cleanup } from "@testing-library/react-native";
3
3
  import configureStore from "redux-mock-store";
4
4
  import { Provider } from "react-redux";
5
5
 
@@ -3,7 +3,10 @@ import memoizee from "memoizee";
3
3
  import * as R from "ramda";
4
4
 
5
5
  import { CellRendererResolver } from "@applicaster/zapp-react-native-ui-components/Components/CellRendererResolver";
6
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
6
+ import {
7
+ usePlugins,
8
+ useCellStyles,
9
+ } from "@applicaster/zapp-react-native-redux";
7
10
  import { useDimensions } from "../layout";
8
11
  import { useIsRTL } from "../../localizationUtils";
9
12
 
@@ -53,7 +56,8 @@ export function useCellResolver({
53
56
  updateForInactiveScreens: false,
54
57
  });
55
58
 
56
- const { plugins, cellStyles } = usePickFromState(["plugins", "cellStyles"]);
59
+ const plugins = usePlugins();
60
+ const cellStyles = useCellStyles();
57
61
  const isRTL = useIsRTL();
58
62
 
59
63
  const options = {
@@ -1,8 +1,14 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import * as React from "react";
3
3
 
4
+ import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
5
+
4
6
  import { findComponentByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
5
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
+ import {
8
+ usePlugins,
9
+ useAppSelector,
10
+ selectComponents,
11
+ } from "@applicaster/zapp-react-native-redux";
6
12
 
7
13
  type Decorator = (component: React.Component<any>) => React.Component<any>;
8
14
  type Watcher = Array<any>;
@@ -15,9 +21,11 @@ export function useComponentResolver(
15
21
  { componentType, decorators }: Props,
16
22
  watchers?: Watcher
17
23
  ): React.ComponentType<any> {
18
- const { plugins, components } = usePickFromState(["plugins", "components"]);
24
+ const plugins = usePlugins();
25
+
26
+ const components = useAppSelector(selectComponents);
19
27
 
20
- return React.useMemo(
28
+ const component = React.useMemo(
21
29
  () =>
22
30
  findComponentByType({
23
31
  components,
@@ -27,4 +35,12 @@ export function useComponentResolver(
27
35
  }),
28
36
  watchers
29
37
  );
38
+
39
+ if (!component) {
40
+ coreLogger.warn({
41
+ message: `useComponentResolver: Component of type ${componentType} not found`,
42
+ });
43
+ }
44
+
45
+ return component;
30
46
  }
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { Provider } from "react-redux";
3
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
- import thunk from "redux-thunk";
5
+ import { thunk } from "redux-thunk";
6
6
 
7
7
  const mockStore = configureStore([thunk]);
8
8
 
@@ -0,0 +1,103 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useCurrentScreenIsHook } from "../useCurrentScreenIsHook";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
6
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
7
+
8
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
9
+ jest.mock("@applicaster/zapp-react-native-utils/utils");
10
+ jest.mock("@applicaster/zapp-react-native-utils/booleanUtils");
11
+
12
+ const mockUseNavigation = useNavigation as jest.Mock;
13
+ const mockLast = last as jest.Mock;
14
+ const mockToBoolean = toBooleanWithDefaultFalse as jest.Mock;
15
+
16
+ describe("useCurrentScreenIsHook", () => {
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+
20
+ // sensible defaults
21
+ mockUseNavigation.mockReturnValue({ mainStack: [] });
22
+ mockLast.mockReturnValue(undefined);
23
+ mockToBoolean.mockReturnValue(false);
24
+ });
25
+
26
+ it("returns true when last route includes 'hook'", () => {
27
+ const stack = [{ route: "some-hook-screen" }];
28
+
29
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
30
+ mockLast.mockReturnValue(stack[0]);
31
+ mockToBoolean.mockReturnValue(true);
32
+
33
+ const { result } = renderHook(() => useCurrentScreenIsHook());
34
+
35
+ expect(mockLast).toHaveBeenCalledWith(stack);
36
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
37
+ expect(result.current).toBe(true);
38
+ });
39
+
40
+ it("returns false when last route does not include 'hook'", () => {
41
+ const stack = [{ route: "home-screen" }];
42
+
43
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
44
+ mockLast.mockReturnValue(stack[0]);
45
+ mockToBoolean.mockReturnValue(false);
46
+
47
+ const { result } = renderHook(() => useCurrentScreenIsHook());
48
+
49
+ expect(mockToBoolean).toHaveBeenCalledWith(false);
50
+ expect(result.current).toBe(false);
51
+ });
52
+
53
+ it("returns false when route is undefined", () => {
54
+ const stack = [{}];
55
+
56
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
57
+ mockLast.mockReturnValue(stack[0]);
58
+ mockToBoolean.mockReturnValue(false);
59
+
60
+ const { result } = renderHook(() => useCurrentScreenIsHook());
61
+
62
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
63
+ expect(result.current).toBe(false);
64
+ });
65
+
66
+ it("returns false when last(mainStack) is undefined (empty stack)", () => {
67
+ mockUseNavigation.mockReturnValue({ mainStack: [] });
68
+ mockLast.mockReturnValue(undefined);
69
+ mockToBoolean.mockReturnValue(false);
70
+
71
+ const { result } = renderHook(() => useCurrentScreenIsHook());
72
+
73
+ expect(mockLast).toHaveBeenCalledWith([]);
74
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
75
+ expect(result.current).toBe(false);
76
+ });
77
+
78
+ it("uses default empty array when mainStack is undefined", () => {
79
+ mockUseNavigation.mockReturnValue({});
80
+ mockLast.mockReturnValue(undefined);
81
+ mockToBoolean.mockReturnValue(false);
82
+
83
+ const { result } = renderHook(() => useCurrentScreenIsHook());
84
+
85
+ expect(mockLast).toHaveBeenCalledWith([]);
86
+ expect(result.current).toBe(false);
87
+ });
88
+
89
+ it("passes correct boolean result from includes('hook')", () => {
90
+ const stack = [{ route: "hook" }];
91
+
92
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
93
+ mockLast.mockReturnValue(stack[0]);
94
+
95
+ // simulate actual includes result flowing through
96
+ mockToBoolean.mockImplementation((val) => Boolean(val));
97
+
98
+ const { result } = renderHook(() => useCurrentScreenIsHook());
99
+
100
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
101
+ expect(result.current).toBe(true);
102
+ });
103
+ });
@@ -0,0 +1,94 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useCurrentScreenIsStartupHook } from "../useCurrentScreenIsStartupHook";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
6
+
7
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
8
+ jest.mock("@applicaster/zapp-react-native-utils/arrayUtils");
9
+
10
+ const mockUseNavigation = useNavigation as jest.Mock;
11
+ const mockIsFilledArray = isFilledArray as jest.Mock;
12
+
13
+ describe("useCurrentScreenIsStartupHook", () => {
14
+ beforeEach(() => {
15
+ jest.clearAllMocks();
16
+ });
17
+
18
+ it("returns true when startUpHooks is a filled array", () => {
19
+ mockUseNavigation.mockReturnValue({
20
+ startUpHooks: ["hook1"],
21
+ });
22
+
23
+ mockIsFilledArray.mockReturnValue(true);
24
+
25
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
26
+
27
+ expect(result.current).toBe(true);
28
+ expect(mockIsFilledArray).toHaveBeenCalledWith(["hook1"]);
29
+ });
30
+
31
+ it('returns true when startUpHooks is "in_process"', () => {
32
+ mockUseNavigation.mockReturnValue({
33
+ startUpHooks: "in_process",
34
+ });
35
+
36
+ mockIsFilledArray.mockReturnValue(false);
37
+
38
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
39
+
40
+ expect(result.current).toBe(true);
41
+ expect(mockIsFilledArray).toHaveBeenCalledWith("in_process");
42
+ });
43
+
44
+ it("returns false when startUpHooks is empty array", () => {
45
+ mockUseNavigation.mockReturnValue({
46
+ startUpHooks: [],
47
+ });
48
+
49
+ mockIsFilledArray.mockReturnValue(false);
50
+
51
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
52
+
53
+ expect(result.current).toBe(false);
54
+ expect(mockIsFilledArray).toHaveBeenCalledWith([]);
55
+ });
56
+
57
+ it("returns false when startUpHooks is undefined", () => {
58
+ mockUseNavigation.mockReturnValue({
59
+ startUpHooks: undefined,
60
+ });
61
+
62
+ mockIsFilledArray.mockReturnValue(false);
63
+
64
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
65
+
66
+ expect(result.current).toBe(false);
67
+ expect(mockIsFilledArray).toHaveBeenCalledWith(undefined);
68
+ });
69
+
70
+ it("returns false when startUpHooks is null", () => {
71
+ mockUseNavigation.mockReturnValue({
72
+ startUpHooks: null,
73
+ });
74
+
75
+ mockIsFilledArray.mockReturnValue(false);
76
+
77
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
78
+
79
+ expect(result.current).toBe(false);
80
+ expect(mockIsFilledArray).toHaveBeenCalledWith(null);
81
+ });
82
+
83
+ it("prioritizes filled array over string comparison", () => {
84
+ mockUseNavigation.mockReturnValue({
85
+ startUpHooks: ["hook1"],
86
+ });
87
+
88
+ mockIsFilledArray.mockReturnValue(true);
89
+
90
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
91
+
92
+ expect(result.current).toBe(true);
93
+ });
94
+ });
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
 
3
3
  jest.mock(
4
4
  "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration",
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
  import configureStore from "redux-mock-store";
3
3
 
4
4
  const mockStore = configureStore();
@@ -1,16 +1,24 @@
1
1
  import * as React from "react";
2
2
  import { Provider } from "react-redux";
3
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
- import thunk from "redux-thunk";
5
+ import { thunk } from "redux-thunk";
6
6
 
7
7
  const mockStore = configureStore([thunk]);
8
8
 
9
9
  import { useTargetScreenData } from "../useTargetScreenData";
10
10
 
11
11
  describe("useTargetScreenData", function () {
12
- const river_id_2 = {};
13
- const river_id_1 = {};
12
+ const river_id_2 = {
13
+ id: "river_id_2",
14
+ type: "any",
15
+ };
16
+
17
+ const river_id_1 = {
18
+ id: "river_id_1",
19
+ type: "any",
20
+ };
21
+
14
22
  const screenId = "river_id_2";
15
23
  const entry = { id: "test", type: { value: "video" } };
16
24
 
@@ -12,3 +12,7 @@ export {
12
12
  } from "./useScreenContext";
13
13
 
14
14
  export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
15
+
16
+ export { useCurrentScreenIsHook } from "./useCurrentScreenIsHook";
17
+
18
+ export { useCurrentScreenIsStartupHook } from "./useCurrentScreenIsStartupHook";
@@ -0,0 +1,9 @@
1
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
2
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
3
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
4
+
5
+ export const useCurrentScreenIsHook = (): boolean => {
6
+ const { mainStack = [] } = useNavigation();
7
+
8
+ return toBooleanWithDefaultFalse(last(mainStack)?.route?.includes("hook"));
9
+ };
@@ -0,0 +1,8 @@
1
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
2
+ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
3
+
4
+ export const useCurrentScreenIsStartupHook = (): boolean => {
5
+ const { startUpHooks } = useNavigation();
6
+
7
+ return isFilledArray(startUpHooks) || startUpHooks === "in_process";
8
+ };
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
2
+ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
3
3
  import * as R from "ramda";
4
4
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
5
+ import { useRivers } from "../state";
5
6
 
6
7
  export function getTargetScreenData(
7
8
  entry: ZappEntry,
@@ -43,7 +44,8 @@ export function getTargetScreenDataFromEntry(entry: ZappEntry): ZappRiver {
43
44
  }
44
45
 
45
46
  export const useTargetScreenData = (entry: ZappEntry) => {
46
- const { rivers, contentTypes } = usePickFromState(["rivers", "contentTypes"]);
47
+ const rivers = useRivers();
48
+ const contentTypes = useContentTypes();
47
49
 
48
50
  return React.useMemo(
49
51
  () => getTargetScreenData(entry, rivers, contentTypes),