@applicaster/zapp-react-native-utils 12.0.0-rc.7 → 12.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 (98) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +16 -8
  2. package/analyticsUtils/AnalyticsEvents/index.ts +6 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
  5. package/analyticsUtils/analyticsPlugins.ts +25 -0
  6. package/analyticsUtils/events.ts +6 -0
  7. package/analyticsUtils/helpers/hooks.ts +1 -1
  8. package/analyticsUtils/index.tsx +6 -0
  9. package/appUtils/HooksManager/index.js +3 -1
  10. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  11. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  12. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  13. package/appUtils/focusManager/index.ts +76 -56
  14. package/appUtils/focusManager/treeDataStructure/Utils/index.js +74 -34
  15. package/appUtils/focusManager/utils/index.ts +100 -0
  16. package/appUtils/focusManagerAux/index.ts +76 -0
  17. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  18. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
  19. package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
  20. package/appUtils/keyCodes/keys.web.js +1 -0
  21. package/appUtils/orientationHelper.ts +1 -1
  22. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
  23. package/appUtils/playerManager/conts.ts +5 -0
  24. package/appUtils/playerManager/player.ts +47 -4
  25. package/appUtils/playerManager/playerFactory.ts +15 -1
  26. package/appUtils/playerManager/playerNative.ts +35 -0
  27. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
  28. package/appUtils/playerManager/usePlayerState.tsx +13 -1
  29. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
  30. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  31. package/arrayUtils/index.ts +5 -0
  32. package/cellUtils/__tests__/cellUtils.test.ts +48 -0
  33. package/cellUtils/__tests__/fixtures.ts +13 -0
  34. package/cellUtils/index.ts +40 -2
  35. package/dateUtils/index.ts +11 -0
  36. package/focusManager/index.ts +1 -1
  37. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
  38. package/functionUtils/__tests__/functionUtils.test.js +244 -248
  39. package/headersUtils/index.ts +1 -0
  40. package/inflatedUrlUtils/index.ts +4 -4
  41. package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
  42. package/localizationUtils/index.ts +13 -19
  43. package/logger/index.ts +1 -1
  44. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  45. package/manifestUtils/defaultManifestConfigurations/player.js +10 -1
  46. package/manifestUtils/index.js +5 -1
  47. package/manifestUtils/secondaryImage/index.js +18 -15
  48. package/modalState/index.ts +57 -0
  49. package/navigationUtils/index.ts +56 -7
  50. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  51. package/numberUtils/index.ts +9 -18
  52. package/package.json +3 -2
  53. package/playerUtils/configurationGenerator.ts +11 -1
  54. package/pluginUtils/index.ts +11 -7
  55. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  56. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  57. package/reactHooks/cell-click/__tests__/index.test.js +16 -3
  58. package/reactHooks/cell-click/index.ts +14 -14
  59. package/reactHooks/device/index.ts +0 -1
  60. package/reactHooks/device/useIsTablet.tsx +28 -3
  61. package/reactHooks/device/useMemoizedIsTablet.ts +1 -1
  62. package/reactHooks/device/useOrientation.tsx +3 -1
  63. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  64. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  65. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  66. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  67. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
  68. package/reactHooks/index.ts +2 -0
  69. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
  70. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  71. package/reactHooks/layout/index.ts +2 -1
  72. package/reactHooks/layout/types/index.ts +2 -0
  73. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
  74. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
  75. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  76. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  77. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  78. package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
  79. package/reactHooks/navigation/index.ts +234 -81
  80. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  81. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  82. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  83. package/reactHooks/screen/index.ts +4 -0
  84. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  85. package/reactHooks/screen/useScreenContext.ts +4 -4
  86. package/reactHooks/screen/useScreenData.ts +1 -1
  87. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  88. package/reactHooks/state/useRivers.ts +3 -1
  89. package/reactHooks/useListenEventBusEvent.ts +1 -4
  90. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
  91. package/riverComponetsMeasurementProvider/index.tsx +2 -2
  92. package/stringUtils/index.ts +5 -0
  93. package/testUtils/getByTestId.ts +14 -0
  94. package/testUtils/index.tsx +38 -23
  95. package/types.ts +4 -0
  96. package/reactHooks/device/useIsTablet.android.tsx +0 -14
  97. package/reactHooks/device/useIsTablet.ios.tsx +0 -7
  98. package/reactHooks/device/useIsTablet.web.tsx +0 -3
@@ -1,9 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
2
  /* eslint max-len: off */
3
3
 
4
- import React, { useEffect, useMemo } from "react";
4
+ import React, { useContext, useEffect, useMemo } from "react";
5
5
  import { BackHandler, InteractionManager, NativeModules } from "react-native";
6
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
7
+ import { isEmpty } from "ramda";
7
8
 
8
9
  import {
9
10
  useContentTypes,
@@ -12,23 +13,113 @@ import {
12
13
  import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
13
14
 
14
15
  import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
15
- import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
16
+ import {
17
+ LONG_KEY_PRESS_TIMEOUT,
18
+ QUICK_BRICK_NAVBAR,
19
+ QUICK_BRICK_CONTENT,
20
+ } from "@applicaster/quick-brick-core/const";
16
21
  import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/ZappHooksModal";
17
22
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
18
23
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
19
24
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
20
- import { getNavigationProps } from "@applicaster/zapp-react-native-utils/navigationUtils";
21
25
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
22
- import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
26
+ import {
27
+ getNavigationProps,
28
+ getRiverFromRoute,
29
+ getTargetRoute,
30
+ } from "../../navigationUtils";
23
31
  import { platformSelect } from "../../reactUtils";
24
32
  import { useConnectionInfo } from "../connection";
25
33
  import { getTargetScreenData } from "../screen/useTargetScreenData";
26
- import { useNavbarState } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
27
34
 
35
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
36
+ import { useNavbarState } from "../screen";
28
37
  import { useNavigation } from "./useNavigation";
38
+ import { useModalStore } from "../../modalState";
39
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
29
40
 
30
41
  export { useNavigation } from "./useNavigation";
31
42
 
43
+ /**
44
+ * This function helps to decide wether the navbar should be presented on the screen
45
+ * based on route and / or screen Data
46
+ *
47
+ * Currently the scenarios include
48
+ * - players => false
49
+ * - search screen plugin => false
50
+ * - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
51
+ * - screens with `allow_screen_plugin_presentation` in general property => false
52
+ *
53
+ * @param {String} route current route of the screen
54
+ * @param {Object} screenData payload associated with the currently presented screen
55
+ * @returns {Boolean}
56
+ */
57
+ export function isNavBarVisible(
58
+ route: string,
59
+ screenData: ZappRiver = {} as ZappRiver,
60
+ showNavBar: boolean,
61
+ canGoBack: boolean,
62
+ videoModalState: QuickBrickVideoModalState | null = null
63
+ ) {
64
+ /* screenData is not actual navigator.data
65
+ * or navigator.screenData,
66
+ * but navigator.data.screen */
67
+ if (route.includes("playable")) {
68
+ return false;
69
+ }
70
+
71
+ if (
72
+ videoModalState?.mode === "FULLSCREEN" &&
73
+ videoModalState?.visible === true
74
+ ) {
75
+ return false;
76
+ }
77
+
78
+ if (screenData?.type === "qb_search_screen" && !isTV()) {
79
+ return false;
80
+ }
81
+
82
+ /* Match if screen is Hook */
83
+ if (route.startsWith("/hooks/")) {
84
+ const module = screenData?.module;
85
+
86
+ if (module?.presentFullScreen) {
87
+ return false;
88
+ }
89
+
90
+ return module?.showNavBar ?? false;
91
+ }
92
+
93
+ if (screenData?.hookPlugin) {
94
+ const hookPlugin = screenData?.hookPlugin?.module;
95
+
96
+ return (
97
+ hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
98
+ );
99
+ }
100
+
101
+ if (
102
+ screenData?.general?.allow_screen_plugin_presentation ||
103
+ screenData?.general?.hide_app_nav_bar
104
+ ) {
105
+ return false;
106
+ }
107
+
108
+ const hideSecondaryLevel = screenData?.navigations?.some(
109
+ (navigation) => navigation.styles?.hide_secondary_level_menu
110
+ );
111
+
112
+ if (canGoBack && hideSecondaryLevel) {
113
+ return false;
114
+ }
115
+
116
+ if (typeof showNavBar === "boolean" && !showNavBar) {
117
+ return false;
118
+ }
119
+
120
+ return true;
121
+ }
122
+
32
123
  const { ProfilerBridge } = NativeModules;
33
124
 
34
125
  export const usePathname = () => React.useContext(PathnameContext);
@@ -43,6 +134,91 @@ export const useBackHandler = (cb: () => boolean) => {
43
134
  }, [cb]);
44
135
  };
45
136
 
137
+ // starts with modal/
138
+ const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
139
+
140
+ const isVideoModalPathname = (pathname: string) =>
141
+ /^video-modal\//.test(pathname);
142
+
143
+ const isHookModalPathname = (pathname: string) =>
144
+ /^hooks-modal\//.test(pathname);
145
+
146
+ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
147
+
148
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
149
+
150
+ export const useRoute = (): {
151
+ screenData: VariousScreenData;
152
+ pathname: string;
153
+ } => {
154
+ const pathname = usePathname() || "";
155
+ const navigator = useNavigation();
156
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
157
+
158
+ const { plugins, contentTypes, rivers } = usePickFromState([
159
+ "plugins",
160
+ "rivers",
161
+ "contentTypes",
162
+ ]);
163
+
164
+ const { modalState } = useModalStore();
165
+ const hookModalState = useZappHooksModalState();
166
+
167
+ const modalScreenData = modalState.screen;
168
+
169
+ const hookModalScreenData = hookModalState.state.screenData?.payload;
170
+
171
+ const videoModalScreenData =
172
+ navigator.videoModalState?.item &&
173
+ legacyScreenData(
174
+ {
175
+ entry: navigator.videoModalState?.item as ZappEntry,
176
+ screen: getTargetScreenData(
177
+ navigator.videoModalState?.item as ZappEntry,
178
+ rivers,
179
+ contentTypes
180
+ ),
181
+ },
182
+ plugins
183
+ );
184
+
185
+ // There are 4 route scenarios
186
+ // For regular screens take date from navigator stack.
187
+ // is path is model grab screenData from modal state
188
+ // if path is video modal grab screenData from video state
189
+ // if path is hook modal grab screenData from hook state
190
+ // if path is hook grab screenData from screenData
191
+
192
+ if (isModalPathname(pathname)) {
193
+ const screenData = modalScreenData ?? ({} as ZappEntry);
194
+
195
+ return { screenData, pathname };
196
+ }
197
+
198
+ if (isVideoModalPathname(pathname)) {
199
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
200
+
201
+ return { screenData, pathname };
202
+ }
203
+
204
+ if (isHookModalPathname(pathname)) {
205
+ const screenData = hookModalScreenData;
206
+
207
+ return { screenData, pathname };
208
+ }
209
+
210
+ if (isHookPathname(pathname)) {
211
+ return { screenData: screenDataContext, pathname };
212
+ }
213
+
214
+ // Cover cases where screenContext is used before navigation is initialized
215
+ const screenData = isEmpty(screenDataContext)
216
+ ? navigator.screenData
217
+ : screenDataContext;
218
+
219
+ return { screenData, pathname };
220
+ };
221
+
46
222
  type Callbacks = Partial<{
47
223
  handleHookPresent: ({
48
224
  route,
@@ -209,7 +385,7 @@ export const useRunIfLongPress = (
209
385
  React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
210
386
 
211
387
  const resetTimeout = () => {
212
- clearTimeout(pressTimeout.current);
388
+ clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
213
389
  };
214
390
 
215
391
  const startTimeout = (cb: () => void) => {
@@ -231,102 +407,79 @@ export const useRunIfLongPress = (
231
407
  * @returns boolean - navbar visiblity status
232
408
  */
233
409
  export const useIsNavBarVisible = (): boolean => {
234
- const visible = useNavbarState().visible;
410
+ const { visible } = useNavbarState();
235
411
 
236
412
  return useMemo(() => visible, [visible]);
237
413
  };
238
414
 
239
- const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
240
-
241
- const isVideoModalPathname = (pathname: string) =>
242
- /^video-modal\//.test(pathname);
243
-
244
- const isHookModalPathname = (pathname: string) =>
245
- /^hooks-modal\//.test(pathname);
246
-
247
- export const useRoute = () => {
248
- const pathname = usePathname() || "";
415
+ const useGetNavBarTopBorderWidth = (): number => {
249
416
  const navigator = useNavigation();
250
417
 
251
- const { plugins, contentTypes, rivers } = usePickFromState([
252
- "plugins",
253
- "rivers",
254
- "contentTypes",
255
- ]);
418
+ const navProps = getNavigationProps({
419
+ navigator,
420
+ title: "",
421
+ category: "menu",
422
+ });
256
423
 
257
- const currentStack = navigator.getStackForPathname(pathname);
258
- const modalState = navigator.modalState;
259
- const hookModalState = useZappHooksModalState();
424
+ return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
425
+ };
260
426
 
261
- const modalScreenData = modalState.screen;
427
+ const TAB_BAR_HEIGHT_IOS = 49;
428
+ const TAB_BAR_HEIGHT_ANDROID = 56;
262
429
 
263
- const hookModalScreenData = hookModalState.state.screenData?.payload;
430
+ const useGetTabBarHeight = () =>
431
+ platformSelect({
432
+ ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
433
+ android: TAB_BAR_HEIGHT_ANDROID,
434
+ }) as number;
264
435
 
265
- const videoModalScreenData =
266
- navigator.videoModalState?.item &&
267
- legacyScreenData(
268
- {
269
- entry: navigator.videoModalState?.item,
270
- screen: getTargetScreenData(
271
- navigator.videoModalState?.item,
272
- rivers,
273
- contentTypes
274
- ),
275
- },
276
- plugins
277
- );
436
+ export const useGetBottomTabBarHeight = (): number => {
437
+ const topBorderWidth = useGetNavBarTopBorderWidth();
438
+ const tabBarHeight = useGetTabBarHeight();
278
439
 
279
- const currentRouteScreenData = legacyScreenData(
280
- {
281
- screen:
282
- currentStack?.state?.screen ??
283
- navigator.data?.screen ??
284
- ({} as ZappRiver),
285
- entry: currentStack?.state?.entry ?? ({} as ZappEntry),
286
- },
440
+ const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
287
441
 
288
- plugins
289
- );
442
+ return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
443
+ };
290
444
 
291
- // There are 4 route scenarios
292
- // For regular screens take date from navigator stack.
293
- // is path is model grab screenData from modal state
294
- // if path is video modal grab screenData from video state
295
- // if path is hook modal grab screenData from hook state
445
+ // If current screen is active/focused (visible to the user)
446
+ export const useIsScreenActive = () => {
447
+ const pathname = usePathname();
448
+ const { currentRoute, videoModalState } = useNavigation();
296
449
 
297
- const screenData = isModalPathname(pathname)
298
- ? modalScreenData
299
- : isVideoModalPathname(pathname)
300
- ? videoModalScreenData
301
- : isHookModalPathname(pathname)
302
- ? hookModalScreenData
303
- : currentRouteScreenData;
450
+ if (
451
+ videoModalState.visible &&
452
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
453
+ ) {
454
+ return false;
455
+ }
304
456
 
305
- return { screenData, pathname };
457
+ return pathname === currentRoute;
306
458
  };
307
459
 
308
- export const useGetBottomTabBarHeight = (): number => {
309
- const insets = useSafeAreaInsets();
310
- const navigator = useNavigation();
460
+ type Return = (prefix: string) => string;
311
461
 
312
- const navProps = getNavigationProps({
313
- navigator,
314
- title: "",
315
- category: "menu",
316
- });
462
+ export const useUniqueRouteSuffix = (): Return => {
463
+ const pathname = usePathname();
464
+ const { currentRoute } = useNavigation();
317
465
 
318
- const navType = useNavigationType();
319
- const isBottomBarNavigation = navType === MenuTypes.bottomTabBar;
466
+ const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
320
467
 
321
- const TAB_BAR_HEIGHT_IOS = 49;
322
- const TAB_BAR_HEIGHT_ANDROID = 56;
468
+ const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
469
+ return `${prefix}___${suffix}`;
470
+ }, []);
323
471
 
324
- if (!isBottomBarNavigation) return 0;
472
+ return withUniqueRouteSuffix;
473
+ };
325
474
 
326
- const tabBarHeight = platformSelect({
327
- ios: TAB_BAR_HEIGHT_IOS + insets.bottom,
328
- android: TAB_BAR_HEIGHT_ANDROID,
329
- }) as number;
475
+ export const useNavbarId = () => {
476
+ const withUniqueRouteSuffix = useUniqueRouteSuffix();
477
+
478
+ return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
479
+ };
480
+
481
+ export const useContentId = () => {
482
+ const withUniqueRouteSuffix = useUniqueRouteSuffix();
330
483
 
331
- return tabBarHeight + Number(navProps?.styles?.top_border_width ?? 0);
484
+ return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
332
485
  };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { renderHook, cleanup } from "@testing-library/react-hooks";
3
+ import { cleanup, renderHook } from "@testing-library/react-hooks";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { Provider } from "react-redux";
6
6
 
@@ -12,6 +12,8 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
12
12
  useIsRTL: jest.fn(() => mock_rtl_flag),
13
13
  }));
14
14
 
15
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
+
15
17
  const { useCellResolver } = require("../useCellResolver");
16
18
 
17
19
  describe("cellResolver", () => {
@@ -1,7 +1,7 @@
1
1
  // @ts-ignore
2
2
  import { View } from "react-native";
3
3
 
4
- const mockData: NavigationScreenData = {
4
+ const mockData = {
5
5
  screen: {
6
6
  id: "screen-id",
7
7
  name: "screen",
@@ -40,3 +40,5 @@ const mockData: NavigationScreenData = {
40
40
  };
41
41
 
42
42
  export const useScreenContext = jest.fn().mockReturnValue(mockData);
43
+
44
+ export const useNavbarState = () => ({ visible: true });
@@ -3,23 +3,28 @@ import { Provider } from "react-redux";
3
3
  import { renderHook } from "@testing-library/react-hooks";
4
4
  import configureStore from "redux-mock-store";
5
5
  import thunk from "redux-thunk";
6
- import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
7
6
 
8
7
  const mockStore = configureStore([thunk]);
9
8
 
10
- import { useCurrentScreenData } from "../useCurrentScreenData";
11
-
12
- describe("useScreenData", function () {
13
- const river_id_2: ZappRiver = {
14
- name: "River 2",
15
- id: "A1234",
16
- home: false,
17
- home_offline: false,
18
- supports_offline: false,
19
- navigations: [],
20
- hooks: { preload_plugins: [] },
21
- };
22
-
9
+ const river_id_2: ZappRiver = {
10
+ name: "River 2",
11
+ id: "A1234",
12
+ home: false,
13
+ home_offline: false,
14
+ supports_offline: false,
15
+ navigations: [],
16
+ hooks: { preload_plugins: [] },
17
+ };
18
+
19
+ jest.mock("../useScreenContext", () => ({
20
+ useScreenContext: () => ({
21
+ screen: river_id_2,
22
+ }),
23
+ }));
24
+
25
+ const { useCurrentScreenData } = require("../useCurrentScreenData");
26
+
27
+ describe("useScreenData", () => {
23
28
  const river_id_1 = { id: "B5678" };
24
29
 
25
30
  const store = mockStore({
@@ -27,17 +32,10 @@ describe("useScreenData", function () {
27
32
  });
28
33
 
29
34
  const wrapper: React.FC<any> = ({ children }) => (
30
- <NavigationContext.Provider
31
- value={{
32
- currentRoute: "/river/river_id_1/river/river_id_2",
33
- data: { screen: river_id_2 },
34
- }}
35
- >
36
- <Provider store={store}>{children}</Provider>
37
- </NavigationContext.Provider>
35
+ <Provider store={store}>{children}</Provider>
38
36
  );
39
37
 
40
- it("should return river data for the current screen/route", function () {
38
+ it("should return river data for the current screen/route", () => {
41
39
  const { result } = renderHook(() => useCurrentScreenData(), { wrapper });
42
40
 
43
41
  expect(result.current).toBe(river_id_2);
@@ -2,9 +2,13 @@ export { useCurrentScreenData } from "./useCurrentScreenData";
2
2
 
3
3
  export { useTargetScreenData } from "./useTargetScreenData";
4
4
 
5
+ export { useScreenData } from "./useScreenData";
6
+
5
7
  export {
6
8
  useScreenContext,
7
9
  useLegacyScreenData,
8
10
  useNavbarState,
9
11
  useSetNavbarState,
10
12
  } from "./useScreenContext";
13
+
14
+ export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
3
+ import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
4
+ import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
5
+
6
+ export const useScreenBackgroundColor = (screenId: string): string => {
7
+ const { backgroundColor: screenBackgroundColor } =
8
+ useScreenConfiguration(screenId);
9
+
10
+ const theme = useTheme();
11
+
12
+ const themeBackgroundColor = React.useMemo(
13
+ () => theme.app_background_color,
14
+ [theme.app_background_color]
15
+ );
16
+
17
+ const backgroundColor = ifEmptyUseFallback(
18
+ screenBackgroundColor,
19
+ themeBackgroundColor
20
+ );
21
+
22
+ return backgroundColor;
23
+ };
@@ -2,11 +2,12 @@ import { useContext, useMemo } from "react";
2
2
 
3
3
  import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
4
4
  import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
5
- import { useNavigation } from "../navigation";
5
+ import { useNavigation } from "../navigation/useNavigation";
6
6
 
7
7
  import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
8
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
8
9
 
9
- function useScreenContextV2() {
10
+ export function useScreenContextV2() {
10
11
  return useContext(ScreenContext);
11
12
  }
12
13
 
@@ -44,9 +45,8 @@ export function useSetNavbarState() {
44
45
 
45
46
  export function useScreenContext(): NavigationScreenData {
46
47
  const navigator = useNavigation();
48
+ const screenData = useContext(ScreenDataContext);
47
49
 
48
- const screenKey = useMemo(() => navigator?.key, [navigator]);
49
- const screenData = useMemo(() => navigator?.data, [screenKey]);
50
50
  const modalScreenData = navigator?.modalData;
51
51
 
52
52
  const isModal = useModalNavigationContext();
@@ -4,7 +4,7 @@ import { useRivers } from "../state";
4
4
 
5
5
  const logger = utilsLogger.addSubsystem("useScreenData");
6
6
 
7
- export const useScreenData = (screenId?: string): ZappRiver => {
7
+ export const useScreenData = (screenId: string): ZappRiver => {
8
8
  const rivers = useRivers();
9
9
 
10
10
  React.useEffect(() => {
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
3
3
  import * as R from "ramda";
4
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
4
5
 
5
6
  export function getTargetScreenData(
6
7
  entry: ZappEntry,
@@ -35,6 +36,12 @@ export function getTargetScreenData(
35
36
  return rivers?.[screenId];
36
37
  }
37
38
 
39
+ export function getTargetScreenDataFromEntry(entry: ZappEntry): ZappRiver {
40
+ const { rivers, contentTypes } = appStore.get(["rivers", "contentTypes"]);
41
+
42
+ return getTargetScreenData(entry, rivers, contentTypes);
43
+ }
44
+
38
45
  export const useTargetScreenData = (entry: ZappEntry) => {
39
46
  const { rivers, contentTypes } = usePickFromState(["rivers", "contentTypes"]);
40
47
 
@@ -1,7 +1,9 @@
1
1
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
2
2
 
3
+ const riversSelector = ["rivers"];
4
+
3
5
  export const useRivers = () => {
4
- const { rivers } = usePickFromState(["rivers"]);
6
+ const { rivers } = usePickFromState(riversSelector as any);
5
7
 
6
8
  return rivers;
7
9
  };
@@ -13,10 +13,7 @@ export const useListenEventBusEvent = (
13
13
  // TODO: remove after implementing ReactNativeEventBusBridge on iOS
14
14
  if (Platform.OS === "android") {
15
15
  // subscribe to DeviceEventEmitter using subsciption ID
16
- const sub = DeviceEventEmitter.addListener(
17
- subscriptionID,
18
- handler
19
- );
16
+ const sub = DeviceEventEmitter.addListener(subscriptionID, handler);
20
17
 
21
18
  // ask native to start routing these events to RN
22
19
  ReactNativeEventBusBridge.subscribe(subscriptionID, { [source]: events });
@@ -1,8 +1,7 @@
1
- import {
2
- useContentTypes,
3
- usePickFromState,
4
- } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import React from "react";
2
+ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
5
3
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
4
+ import { useRivers } from "../../state";
6
5
 
7
6
  export const useVideoModalScreenData = ():
8
7
  | (ZappEntry & { targetScreen: any }) // TODO: fix ZappEntry type ( was ZappRiver but conflict )
@@ -12,11 +11,13 @@ export const useVideoModalScreenData = ():
12
11
  } = useNavigation();
13
12
 
14
13
  const contentTypes = useContentTypes();
15
- const { rivers } = usePickFromState(["rivers"]);
14
+ const rivers = useRivers();
16
15
 
17
- if (item?.type?.value) {
18
- const screenId = contentTypes[item?.type?.value].screen_id;
16
+ return React.useMemo(() => {
17
+ if (item?.type?.value) {
18
+ const screenId = contentTypes[item?.type?.value].screen_id;
19
19
 
20
- return { ...item, targetScreen: rivers?.[screenId] };
21
- }
20
+ return { ...item, targetScreen: rivers?.[screenId] };
21
+ }
22
+ }, [item]);
22
23
  };
@@ -3,7 +3,7 @@ import { NativeModules, StyleSheet, View } from "react-native";
3
3
  import { getXray } from "@applicaster/zapp-react-native-utils/logger";
4
4
 
5
5
  import { isApplePlatform, isWeb } from "../reactUtils";
6
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
6
+ import { useRivers } from "../reactHooks/state";
7
7
 
8
8
  const layoutReducer = (state, { payload }) => {
9
9
  return state.map((item, index, _state) => ({
@@ -58,7 +58,7 @@ export const ScreenLoadingMeasurements = ({
58
58
  numberOfComponents,
59
59
  riverId,
60
60
  }: Props) => {
61
- const { rivers } = usePickFromState(["rivers"]);
61
+ const rivers = useRivers();
62
62
  const screenData = rivers?.[riverId];
63
63
 
64
64
  const [itemsLayout, dispatchItemLayout] = React.useReducer(
@@ -152,3 +152,8 @@ export function objectToCamelCase(obj) {
152
152
  export function isString(value: unknown): value is string {
153
153
  return typeof value === "string" || value instanceof String;
154
154
  }
155
+
156
+ /** Checks if a value is a non-empty string */
157
+ export function isNotEmptyString(value: unknown): value is string {
158
+ return isString(value) && value.length > 0;
159
+ }