@applicaster/zapp-react-native-utils 12.0.0-alpha.3977160850 → 12.0.0-alpha.4337072244

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 (64) hide show
  1. package/analyticsUtils/AnalyticsEvents/index.ts +6 -0
  2. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  3. package/analyticsUtils/events.ts +6 -0
  4. package/analyticsUtils/index.tsx +6 -0
  5. package/appUtils/HooksManager/index.js +3 -1
  6. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -3
  7. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  8. package/appUtils/focusManager/__tests__/index.test.ts +3 -3
  9. package/appUtils/focusManager/index.ts +141 -56
  10. package/appUtils/focusManager/treeDataStructure/Utils/index.js +73 -34
  11. package/appUtils/focusManager/utils/index.ts +94 -0
  12. package/appUtils/playerManager/conts.ts +5 -0
  13. package/appUtils/playerManager/player.ts +35 -0
  14. package/appUtils/playerManager/playerFactory.ts +12 -10
  15. package/appUtils/playerManager/playerNative.ts +9 -0
  16. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  17. package/arrayUtils/index.ts +5 -0
  18. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  19. package/cellUtils/index.ts +10 -14
  20. package/dateUtils/index.ts +11 -0
  21. package/headersUtils/index.ts +1 -0
  22. package/inflatedUrlUtils/index.ts +4 -4
  23. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  24. package/localizationUtils/index.ts +13 -22
  25. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  26. package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
  27. package/manifestUtils/index.js +5 -1
  28. package/manifestUtils/secondaryImage/index.js +18 -15
  29. package/navigationUtils/index.ts +8 -4
  30. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  31. package/numberUtils/index.ts +9 -18
  32. package/package.json +2 -2
  33. package/playerUtils/configurationGenerator.ts +3 -1
  34. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  35. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  36. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  37. package/reactHooks/cell-click/index.ts +11 -11
  38. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  39. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  40. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  41. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  42. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
  43. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  44. package/reactHooks/layout/types/index.ts +2 -0
  45. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  46. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  47. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  48. package/reactHooks/navigation/__tests__/index.test.tsx +19 -4
  49. package/reactHooks/navigation/index.ts +84 -19
  50. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  51. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  52. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  53. package/reactHooks/screen/index.ts +2 -0
  54. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  55. package/reactHooks/screen/useScreenContext.ts +5 -4
  56. package/reactHooks/screen/useScreenData.ts +1 -1
  57. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  58. package/reactHooks/useListenEventBusEvent.ts +1 -4
  59. package/reactHooks/videoModal/index.ts +0 -3
  60. package/screenState/index.ts +0 -8
  61. package/stringUtils/index.ts +5 -0
  62. package/testUtils/getByTestId.ts +14 -0
  63. package/testUtils/index.tsx +38 -23
  64. package/types.ts +4 -0
@@ -1,4 +1,8 @@
1
+ import React from "react";
2
+
1
3
  import { cleanup, renderHook } from "@testing-library/react-hooks";
4
+ import { Provider } from "react-redux";
5
+ import configureStore from "redux-mock-store";
2
6
 
3
7
  import * as ReactNative from "react-native";
4
8
 
@@ -44,22 +48,47 @@ jest.mock("../../../reactUtils", () => ({
44
48
 
45
49
  jest.mock("../../navigation", () => ({
46
50
  useNavigation: () => null,
51
+ useIsScreenActive: () => true,
47
52
  }));
48
53
 
49
54
  const { Dimensions } = require("react-native");
50
- const { useDimensions } = require("../");
55
+ const { useDimensions } = require("..");
56
+
57
+ const mockStore = configureStore();
58
+
59
+ const getWrapper = () => {
60
+ const store = mockStore({ appData: {} });
61
+
62
+ const Wrapper = ({ children }: { children: React.ReactChild }) => (
63
+ /* @ts-ignore */
64
+ <Provider store={store}>{children}</Provider>
65
+ );
66
+
67
+ return Wrapper;
68
+ };
69
+
70
+ const testHook = (context, params?) => {
71
+ const wrapper = getWrapper();
72
+
73
+ const {
74
+ result,
75
+ result: { current: dimensions },
76
+ } = renderHook(() => useDimensions(context, params), {
77
+ wrapper,
78
+ });
79
+
80
+ return { result, dimensions };
81
+ };
51
82
 
52
83
  describe("useDimensions", () => {
53
84
  it("renders", () => {
54
- const { result } = renderHook(() =>
55
- useDimensions("window", { fullDimensions: true })
56
- );
85
+ const { result } = testHook("window", { fullDimensions: true });
57
86
 
58
87
  expect(result).toBeDefined();
59
88
  });
60
89
 
61
90
  it("sets event listener", () => {
62
- renderHook(() => useDimensions("window", { fullDimensions: true }));
91
+ testHook("window", { fullDimensions: true });
63
92
 
64
93
  expect(Dimensions.addEventListener).toBeCalledWith(
65
94
  "change",
@@ -68,16 +97,14 @@ describe("useDimensions", () => {
68
97
  });
69
98
 
70
99
  it("removes event listener", () => {
71
- renderHook(() => useDimensions("window", { fullDimensions: true }));
100
+ testHook("window", { fullDimensions: true });
72
101
  cleanup();
73
102
 
74
103
  expect(mockRemoveFn).toBeCalled();
75
104
  });
76
105
 
77
106
  it("Returns full dimensions object", () => {
78
- const {
79
- result: { current: dimensions },
80
- } = renderHook(() => useDimensions("window", { fullDimensions: true }));
107
+ const { dimensions } = testHook("window", { fullDimensions: true });
81
108
 
82
109
  expect(dimensions).toHaveProperty("height");
83
110
  expect(dimensions).toHaveProperty("width");
@@ -86,20 +113,17 @@ describe("useDimensions", () => {
86
113
  });
87
114
 
88
115
  it("Returns shorthand dimensions object", () => {
89
- const {
90
- result: { current: dimensions },
91
- } = renderHook(() => useDimensions("window"));
116
+ const { dimensions } = testHook("window");
92
117
 
93
118
  expect(dimensions).toHaveProperty("height");
94
119
  expect(dimensions).toHaveProperty("width");
95
120
  });
96
121
 
97
122
  it("Returns the device info object", () => {
98
- const {
99
- result: { current: dimensions },
100
- } = renderHook(() =>
101
- useDimensions("window", { fullDimensions: true, deviceInfo: true })
102
- );
123
+ const { dimensions } = testHook("window", {
124
+ fullDimensions: true,
125
+ deviceInfo: true,
126
+ });
103
127
 
104
128
  expect(dimensions).toHaveProperty("height");
105
129
  expect(dimensions).toHaveProperty("width");
@@ -112,10 +136,7 @@ describe("useDimensions", () => {
112
136
  it("applies the scale on TV, and screen context", () => {
113
137
  tv_flag = true;
114
138
  const { screen } = mocked_return_value(tv_flag);
115
-
116
- const {
117
- result: { current: dimensions },
118
- } = renderHook(() => useDimensions("screen"));
139
+ const { dimensions } = testHook("screen");
119
140
 
120
141
  expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
121
142
  expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
@@ -127,10 +148,7 @@ describe("useDimensions", () => {
127
148
  it("doesn't apply the scale on mobile with screen context", () => {
128
149
  tv_flag = false;
129
150
  const { screen } = mocked_return_value(tv_flag);
130
-
131
- const {
132
- result: { current: dimensions },
133
- } = renderHook(() => useDimensions("screen"));
151
+ const { dimensions } = testHook("screen");
134
152
 
135
153
  expect(dimensions).toHaveProperty("height", screen.height);
136
154
  expect(dimensions).toHaveProperty("width", screen.width);
@@ -140,10 +158,7 @@ describe("useDimensions", () => {
140
158
  it("doesn't apply the scale on TV with window context", () => {
141
159
  tv_flag = true;
142
160
  const { window } = mocked_return_value(tv_flag);
143
-
144
- const {
145
- result: { current: dimensions },
146
- } = renderHook(() => useDimensions("window"));
161
+ const { dimensions } = testHook("window");
147
162
 
148
163
  expect(dimensions).toHaveProperty("height", window.height);
149
164
  expect(dimensions).toHaveProperty("width", window.width);
@@ -3,13 +3,15 @@ import { isTablet } from "../isTablet";
3
3
  /**
4
4
  * Returns an object with additional device info that can be used to determine if tablet
5
5
  * @param {Number} dimensions - Dimensions object passed to the function
6
+ * @param {Object} appData - application data object passed to the function
6
7
  * @returns {DeviceInfo} deviceInfo - returns an object with scale, isTablet, and orientation
7
8
  */
8
- export const getDeviceInfo = (dimensions) => {
9
+ export const getDeviceInfo = (dimensions, appData) => {
9
10
  const scale = dimensions?.scale;
10
11
  const isLandscape = dimensions?.width > dimensions?.height;
11
12
  const orientation = isLandscape ? "landscape" : "portrait";
12
13
  const tablet = isTablet(dimensions, orientation) || false;
14
+ const isTabletLandscape = tablet && !appData?.isTabletPortrait;
13
15
 
14
- return { scale, isTablet: tablet, orientation };
16
+ return { scale, isTablet: tablet, orientation, isTabletLandscape };
15
17
  };
@@ -2,6 +2,7 @@ type DeviceInfo = {
2
2
  isTablet: boolean;
3
3
  scale: number;
4
4
  orientation: string;
5
+ isTabletLandscape: boolean;
5
6
  };
6
7
 
7
8
  type RNDimensions = {
@@ -20,6 +21,7 @@ export type Options = {
20
21
  excludeStatusBar?: boolean;
21
22
  rounded?: boolean;
22
23
  deviceInfo?: boolean;
24
+ updateForInactiveScreens?: boolean;
23
25
  };
24
26
 
25
27
  export type Context = "window" | "screen";
@@ -1,13 +1,16 @@
1
- import { useState, useLayoutEffect, useRef, useMemo } from "react";
1
+ import { useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
 
3
3
  import * as R from "ramda";
4
4
 
5
5
  import { Dimensions, Platform, StatusBar } from "react-native";
6
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
+
6
8
  import { isTV } from "../../../reactUtils";
7
9
 
8
10
  import { Options, UseDimensions } from "../types";
9
11
  import { getDeviceInfo } from "../getDeviceInfo";
10
12
  import { getInitialDimensions } from "./helpers";
13
+ import { useIsScreenActive } from "../../navigation";
11
14
 
12
15
  function compensateForScaleIfNeeded(context) {
13
16
  return function () {
@@ -32,8 +35,11 @@ const statusBarHeight = StatusBar?.currentHeight;
32
35
  */
33
36
  export const useDimensions: UseDimensions = (
34
37
  context = "window",
35
- fullDimensions = { fullDimensions: false }
38
+ fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
36
39
  ) => {
40
+ const isActive = useIsScreenActive();
41
+ const { appData } = usePickFromState(["appData"]);
42
+
37
43
  if (typeof fullDimensions === "boolean") {
38
44
  // eslint-disable-next-line no-console
39
45
  console.warn(
@@ -47,7 +53,7 @@ export const useDimensions: UseDimensions = (
47
53
  : { ...fullDimensions };
48
54
 
49
55
  const [dimensions, setDimensions] = useState(getInitialDimensions(context));
50
- const deviceInfo = useRef(getDeviceInfo(dimensions));
56
+ const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
51
57
 
52
58
  const applyOptions = R.compose(
53
59
  R.when(() => options.deviceInfo, R.assoc("deviceInfo", deviceInfo.current)),
@@ -73,7 +79,7 @@ export const useDimensions: UseDimensions = (
73
79
 
74
80
  if (newDimensions.width === newDimensions.height) {
75
81
  /**
76
- * Ignoring case occured on iOS when Dimensions.get sometimes returning
82
+ * Ignoring case occurred on iOS when Dimensions.get sometimes returning
77
83
  * wrong `window` sizes
78
84
  * when switch background -> foreground state.
79
85
  * ( TODO fix when 1:1 aspect ratio will be used )
@@ -81,8 +87,8 @@ export const useDimensions: UseDimensions = (
81
87
 
82
88
  // eslint-disable-next-line no-console
83
89
  console.log("change: wrong values - width equal to height, ignoring");
84
- } else {
85
- deviceInfo.current = getDeviceInfo(newDimensions);
90
+ } else if (isActive || options.updateForInactiveScreens) {
91
+ deviceInfo.current = getDeviceInfo(newDimensions, appData);
86
92
  setDimensions(newDimensions);
87
93
  }
88
94
  };
@@ -92,7 +98,7 @@ export const useDimensions: UseDimensions = (
92
98
  return () => {
93
99
  activeSubscription.remove();
94
100
  };
95
- }, []);
101
+ }, [isActive]);
96
102
 
97
103
  const memoizedDimensions = useMemo(() => {
98
104
  return { ...applyOptions(dimensions), statusBarHeight };
@@ -15,11 +15,26 @@ export const mockMenu: ZappNavigation = {
15
15
  // preset_id?: null | unknown;
16
16
  };
17
17
 
18
+ export const useRoute = jest.fn(() => ({
19
+ screenData: {
20
+ name: "someName",
21
+ },
22
+ pathname: "someRoute",
23
+ }));
24
+
18
25
  export const useNavigation = jest.fn(() => ({
19
26
  data: {},
27
+ screenData: {
28
+ name: "someName",
29
+ },
30
+ activeRiver: {
31
+ id: "someId",
32
+ },
20
33
  currentRoute: "someRoute",
21
34
  }));
22
35
 
23
36
  export const useNavigationPluginData = jest.fn().mockReturnValue(mockMenu);
24
37
 
25
38
  export const useIsNavBarVisible = jest.fn().mockReturnValue(true);
39
+
40
+ export const useIsScreenActive = jest.fn().mockReturnValue(true);
@@ -0,0 +1,7 @@
1
+ export const useNavigation = jest.fn(() => ({
2
+ data: {},
3
+ screenData: {
4
+ name: "someName",
5
+ },
6
+ currentRoute: "someRoute",
7
+ }));
@@ -45,10 +45,19 @@ const videoItem = {
45
45
  type: { value: "video" },
46
46
  };
47
47
 
48
+ const mockGetStackForPathname = jest.fn().mockReturnValue(homeStack);
49
+
48
50
  const mainStackNavigator = {
49
- getStackForPathname: jest.fn().mockReturnValue(homeStack),
51
+ getStackForPathname: mockGetStackForPathname,
50
52
  getModalState: () => {},
51
53
  videoModalState: {},
54
+ canGoBack: jest.fn(),
55
+ };
56
+
57
+ const _createWrapper = (Wrapper, props) => {
58
+ return function CreatedWrapper({ children }: any) {
59
+ return <Wrapper {...props}>{children}</Wrapper>;
60
+ };
52
61
  };
53
62
 
54
63
  const videoModalNavigator = {
@@ -85,10 +94,16 @@ const store = mockStore({
85
94
  contentTypes,
86
95
  });
87
96
 
88
- const mainStackWrapper = ({ children }) => (
97
+ const mainStackWrapper = ({
98
+ children,
99
+ navigator = {},
100
+ pathname = homeStack.route,
101
+ }) => (
89
102
  <Provider store={store}>
90
- <NavigationContext.Provider value={mainStackNavigator}>
91
- <PathnameContext.Provider value={homeStack.route}>
103
+ <NavigationContext.Provider
104
+ value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
105
+ >
106
+ <PathnameContext.Provider value={pathname}>
92
107
  {children}
93
108
  </PathnameContext.Provider>
94
109
  </NavigationContext.Provider>
@@ -19,9 +19,9 @@ import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Co
19
19
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
20
20
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
21
21
  import {
22
+ getNavigationProps,
22
23
  getRiverFromRoute,
23
24
  getTargetRoute,
24
- getNavigationProps,
25
25
  } from "../../navigationUtils";
26
26
  import { platformSelect } from "../../reactUtils";
27
27
  import { useConnectionInfo } from "../connection";
@@ -146,6 +146,15 @@ export const useRoute = (): {
146
146
  pathname: string;
147
147
  } => {
148
148
  const pathname = usePathname() || "";
149
+
150
+ /**
151
+ * compose `useRoute()` output data
152
+ */
153
+ const composeRouteData = (screenData: VariousScreenData) => ({
154
+ screenData,
155
+ pathname,
156
+ });
157
+
149
158
  const navigator = useNavigation();
150
159
 
151
160
  const { plugins, contentTypes, rivers } = usePickFromState([
@@ -157,9 +166,7 @@ export const useRoute = (): {
157
166
  const currentStack = navigator.getStackForPathname(pathname);
158
167
  const { modalState } = useModalStore();
159
168
  const hookModalState = useZappHooksModalState();
160
-
161
169
  const modalScreenData = modalState.screen;
162
-
163
170
  const hookModalScreenData = hookModalState.state.screenData?.payload;
164
171
 
165
172
  const videoModalScreenData =
@@ -193,35 +200,63 @@ export const useRoute = (): {
193
200
  // if path is hook grab screenData from screenData
194
201
 
195
202
  if (isModalPathname(pathname)) {
196
- const screenData = modalScreenData ?? ({} as ZappEntry);
197
-
198
- return { screenData, pathname };
203
+ return composeRouteData(modalScreenData ?? ({} as ZappEntry));
199
204
  }
200
205
 
201
206
  if (isVideoModalPathname(pathname)) {
202
- const screenData = videoModalScreenData as LegacyNavigationScreenData;
203
-
204
- return { screenData, pathname };
207
+ return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
205
208
  }
206
209
 
207
210
  if (isHookModalPathname(pathname)) {
208
- const screenData = hookModalScreenData;
209
-
210
- return { screenData, pathname };
211
+ return composeRouteData(hookModalScreenData);
211
212
  }
212
213
 
213
214
  if (isHookPathname(pathname)) {
214
- const screenData =
215
- "hookPlugin" in currentRouteScreenData
216
- ? currentRouteScreenData
217
- : navigator.screenData;
215
+ /**
216
+ * HACK
217
+ *
218
+ * This condition relies on hacky approach to get the current hook screen data
219
+ * using navigator.screenData for some cases.
220
+ * This is used when hook is in sequence.
221
+ */
222
+
223
+ // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
224
+ if (!currentStack) {
225
+ return composeRouteData(navigator.screenData);
226
+ }
227
+
228
+ const isValidHookInCurrentRouteScreenData =
229
+ "hookPlugin" in currentRouteScreenData &&
230
+ !!currentRouteScreenData.hookPlugin?.module;
231
+
232
+ let screenData;
218
233
 
219
- return { screenData, pathname };
234
+ // case 2: stack has valid hook data
235
+ if (isValidHookInCurrentRouteScreenData) {
236
+ screenData = currentRouteScreenData;
237
+ }
238
+
239
+ const navigatorScreenData = navigator.screenData as NavigatorEntry;
240
+
241
+ // case 3: current hookPlugin is missing weight, but navigator.screenData has weight, use navigator.screenData
242
+ if (
243
+ screenData.hookPlugin.identifier ===
244
+ navigatorScreenData?.hookPlugin?.identifier &&
245
+ !screenData.hookPlugin?.weight &&
246
+ navigatorScreenData?.hookPlugin?.weight
247
+ ) {
248
+ screenData = navigator.screenData;
249
+ }
250
+
251
+ return composeRouteData(screenData);
220
252
  }
221
253
 
222
- const screenData = currentRouteScreenData;
254
+ // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
255
+ if (!currentStack) {
256
+ return composeRouteData(navigator.screenData);
257
+ }
223
258
 
224
- return { screenData, pathname };
259
+ return composeRouteData(currentRouteScreenData);
225
260
  };
226
261
 
227
262
  type Callbacks = Partial<{
@@ -446,3 +481,33 @@ export const useGetBottomTabBarHeight = (): number => {
446
481
 
447
482
  return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
448
483
  };
484
+
485
+ // If current screen is active/focused (visible to the user)
486
+ export const useIsScreenActive = () => {
487
+ const pathname = usePathname();
488
+ const { currentRoute, videoModalState } = useNavigation();
489
+
490
+ if (
491
+ videoModalState.visible &&
492
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
493
+ ) {
494
+ return false;
495
+ }
496
+
497
+ return pathname === currentRoute;
498
+ };
499
+
500
+ type Return = (prefix: string) => string;
501
+
502
+ export const useUniqueRouteSuffix = (): Return => {
503
+ const pathname = usePathname();
504
+ const { currentRoute } = useNavigation();
505
+
506
+ const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
507
+
508
+ const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
509
+ return `${prefix}___${suffix}`;
510
+ }, []);
511
+
512
+ return withUniqueRouteSuffix;
513
+ };
@@ -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);
@@ -10,3 +10,5 @@ export {
10
10
  useNavbarState,
11
11
  useSetNavbarState,
12
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/Components/Layout/TV";
8
9
 
9
- function useScreenContextV2() {
10
+ export function useScreenContextV2() {
10
11
  return useContext(ScreenContext);
11
12
  }
12
13
 
@@ -45,8 +46,8 @@ export function useSetNavbarState() {
45
46
  export function useScreenContext(): NavigationScreenData {
46
47
  const navigator = useNavigation();
47
48
 
48
- const screenKey = useMemo(() => navigator?.key, [navigator]);
49
- const screenData = useMemo(() => navigator?.data, [screenKey]);
49
+ const screenData = useContext(ScreenDataContext);
50
+
50
51
  const modalScreenData = navigator?.modalData;
51
52
 
52
53
  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
 
@@ -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 });