@applicaster/zapp-react-native-utils 12.0.0-alpha.9262886003 → 12.0.0-alpha.9417984401

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 (100) hide show
  1. package/analyticsUtils/AnalyticPlayerListener.ts +141 -0
  2. package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
  5. package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
  6. package/analyticsUtils/analyticsPlugins.ts +25 -0
  7. package/analyticsUtils/events.ts +12 -0
  8. package/analyticsUtils/index.tsx +12 -0
  9. package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
  10. package/appUtils/HooksManager/index.js +3 -1
  11. package/appUtils/accessibilityManager/const.ts +50 -0
  12. package/appUtils/accessibilityManager/hooks.ts +40 -0
  13. package/appUtils/accessibilityManager/index.ts +166 -0
  14. package/appUtils/accessibilityManager/logger.ts +5 -0
  15. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  16. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  17. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  18. package/appUtils/focusManager/index.ts +76 -57
  19. package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -44
  20. package/appUtils/focusManager/utils/index.ts +100 -0
  21. package/appUtils/focusManagerAux/index.ts +76 -0
  22. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  23. package/appUtils/index.js +2 -0
  24. package/appUtils/keyCodes/keys.web.js +8 -0
  25. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  26. package/appUtils/platform/const.ts +25 -0
  27. package/appUtils/platform/index.ts +3 -0
  28. package/appUtils/platform/platformUtils.ts +217 -0
  29. package/appUtils/playerManager/conts.ts +6 -0
  30. package/appUtils/playerManager/index.ts +20 -32
  31. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  32. package/appUtils/playerManager/player.ts +44 -3
  33. package/appUtils/playerManager/playerFactory.ts +13 -11
  34. package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
  35. package/appUtils/playerManager/playerNative.ts +15 -15
  36. package/appUtils/playerManager/usePlayerControllerSetup.tsx +8 -2
  37. package/appUtils/playerManager/usePlayerState.tsx +19 -34
  38. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  39. package/arrayUtils/index.ts +5 -0
  40. package/booleanUtils/index.ts +4 -4
  41. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  42. package/cellUtils/index.ts +48 -19
  43. package/dateUtils/index.ts +11 -0
  44. package/functionUtils/index.ts +38 -0
  45. package/headersUtils/index.ts +1 -0
  46. package/index.d.ts +15 -0
  47. package/inflatedUrlUtils/index.ts +4 -4
  48. package/keyboardState/index.ts +0 -0
  49. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  50. package/localizationUtils/index.ts +13 -22
  51. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  52. package/manifestUtils/defaultManifestConfigurations/player.js +123 -1
  53. package/manifestUtils/index.js +5 -1
  54. package/manifestUtils/keys.js +2 -1
  55. package/manifestUtils/secondaryImage/index.js +18 -15
  56. package/navigationUtils/index.ts +48 -0
  57. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  58. package/numberUtils/__tests__/toNumber.test.ts +2 -2
  59. package/numberUtils/index.ts +9 -18
  60. package/package.json +2 -2
  61. package/playerUtils/configurationGenerator.ts +123 -1
  62. package/playerUtils/imaScriptDom.ts +59 -0
  63. package/pluginUtils/index.ts +9 -0
  64. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  65. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  66. package/reactHooks/cell-click/__tests__/index.test.js +10 -1
  67. package/reactHooks/cell-click/index.ts +12 -12
  68. package/reactHooks/debugging/__tests__/index.test.js +81 -11
  69. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  70. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  71. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  72. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  73. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  74. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  75. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
  76. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  77. package/reactHooks/layout/types/index.ts +2 -0
  78. package/reactHooks/layout/useDimensions/useDimensions.ts +15 -7
  79. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  80. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  81. package/reactHooks/navigation/__tests__/index.test.tsx +11 -8
  82. package/reactHooks/navigation/index.ts +64 -21
  83. package/reactHooks/player/useAutoSeek.tsx +9 -7
  84. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  85. package/reactHooks/resolvers/useCellResolver.ts +5 -1
  86. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  87. package/reactHooks/screen/index.ts +2 -0
  88. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  89. package/reactHooks/screen/useScreenContext.ts +3 -3
  90. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  91. package/reactHooks/useConfiguration.ts +2 -2
  92. package/reactUtils/index.ts +104 -0
  93. package/screenState/index.ts +0 -8
  94. package/stringUtils/index.ts +5 -0
  95. package/testUtils/getByTestId.ts +14 -0
  96. package/testUtils/index.tsx +24 -22
  97. package/types.ts +4 -0
  98. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  99. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  100. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -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,18 +87,20 @@ 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
  };
89
95
 
90
96
  const activeSubscription = Dimensions.addEventListener("change", handler);
91
97
 
98
+ handler({ [context]: Dimensions.get(context) });
99
+
92
100
  return () => {
93
101
  activeSubscription.remove();
94
102
  };
95
- }, []);
103
+ }, [isActive]);
96
104
 
97
105
  const memoizedDimensions = useMemo(() => {
98
106
  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);
@@ -1,4 +1,7 @@
1
1
  export const useNavigation = jest.fn(() => ({
2
2
  data: {},
3
+ screenData: {
4
+ name: "someName",
5
+ },
3
6
  currentRoute: "someRoute",
4
7
  }));
@@ -1,12 +1,13 @@
1
1
  import React from "react";
2
2
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
3
3
  import { renderHook } from "@testing-library/react-hooks";
4
- import { useRoute, isNavBarVisible } from "../";
4
+ import { isNavBarVisible, useRoute } from "../";
5
5
  import { Provider } from "react-redux";
6
6
  import configureMockStore from "redux-mock-store";
7
7
  import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
8
8
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
9
9
  import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
10
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
10
11
 
11
12
  const plugins = [];
12
13
 
@@ -100,13 +101,15 @@ const mainStackWrapper = ({
100
101
  pathname = homeStack.route,
101
102
  }) => (
102
103
  <Provider store={store}>
103
- <NavigationContext.Provider
104
- value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
105
- >
106
- <PathnameContext.Provider value={pathname}>
107
- {children}
108
- </PathnameContext.Provider>
109
- </NavigationContext.Provider>
104
+ <ScreenDataContext.Provider value={homeStack.state}>
105
+ <NavigationContext.Provider
106
+ value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
107
+ >
108
+ <PathnameContext.Provider value={pathname}>
109
+ {children}
110
+ </PathnameContext.Provider>
111
+ </NavigationContext.Provider>
112
+ </ScreenDataContext.Provider>
110
113
  </Provider>
111
114
  );
112
115
 
@@ -1,7 +1,7 @@
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
7
 
@@ -12,25 +12,30 @@ import {
12
12
  import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
13
13
 
14
14
  import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
15
- import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
15
+ import {
16
+ LONG_KEY_PRESS_TIMEOUT,
17
+ QUICK_BRICK_NAVBAR,
18
+ QUICK_BRICK_CONTENT,
19
+ } from "@applicaster/quick-brick-core/const";
16
20
  import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/ZappHooksModal";
17
21
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
18
22
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
19
23
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
20
24
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
21
25
  import {
26
+ getNavigationProps,
22
27
  getRiverFromRoute,
23
28
  getTargetRoute,
24
- getNavigationProps,
25
29
  } from "../../navigationUtils";
26
30
  import { platformSelect } from "../../reactUtils";
27
31
  import { useConnectionInfo } from "../connection";
28
32
  import { getTargetScreenData } from "../screen/useTargetScreenData";
29
33
 
30
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
34
+ import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
31
35
  import { useNavbarState } from "../screen";
32
36
  import { useNavigation } from "./useNavigation";
33
37
  import { useModalStore } from "../../modalState";
38
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
34
39
 
35
40
  export { useNavigation } from "./useNavigation";
36
41
 
@@ -73,6 +78,10 @@ export function isNavBarVisible(
73
78
  return false;
74
79
  }
75
80
 
81
+ if (screenData?.plugin_type === "login" && isTV()) {
82
+ return false;
83
+ }
84
+
76
85
  /* Match if screen is Hook */
77
86
  if (route.startsWith("/hooks/")) {
78
87
  const module = screenData?.module;
@@ -147,6 +156,7 @@ export const useRoute = (): {
147
156
  } => {
148
157
  const pathname = usePathname() || "";
149
158
  const navigator = useNavigation();
159
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
150
160
 
151
161
  const { plugins, contentTypes, rivers } = usePickFromState([
152
162
  "plugins",
@@ -154,7 +164,6 @@ export const useRoute = (): {
154
164
  "contentTypes",
155
165
  ]);
156
166
 
157
- const currentStack = navigator.getStackForPathname(pathname);
158
167
  const { modalState } = useModalStore();
159
168
  const hookModalState = useZappHooksModalState();
160
169
 
@@ -176,15 +185,6 @@ export const useRoute = (): {
176
185
  plugins
177
186
  );
178
187
 
179
- const currentRouteScreenData = legacyScreenData(
180
- {
181
- screen: currentStack?.state?.screen ?? navigator.data?.screen ?? {},
182
- entry: currentStack?.state?.entry ?? {},
183
- } as NavigationScreenData,
184
-
185
- plugins
186
- );
187
-
188
188
  // There are 4 route scenarios
189
189
  // For regular screens take date from navigator stack.
190
190
  // is path is model grab screenData from modal state
@@ -211,15 +211,10 @@ export const useRoute = (): {
211
211
  }
212
212
 
213
213
  if (isHookPathname(pathname)) {
214
- const screenData =
215
- "hookPlugin" in currentRouteScreenData
216
- ? currentRouteScreenData
217
- : navigator.screenData;
218
-
219
- return { screenData, pathname };
214
+ return { screenData: screenDataContext, pathname };
220
215
  }
221
216
 
222
- const screenData = currentRouteScreenData;
217
+ const screenData = screenDataContext;
223
218
 
224
219
  return { screenData, pathname };
225
220
  };
@@ -446,3 +441,51 @@ export const useGetBottomTabBarHeight = (): number => {
446
441
 
447
442
  return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
448
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
+ };
@@ -1,5 +1,4 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import * as R from "ramda";
3
2
  import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
4
3
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
5
4
  import {
@@ -17,10 +16,6 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
17
16
  const intervalTimer = React.useRef(null);
18
17
  const prevRunning = usePrevious(isRunning);
19
18
 
20
- const setIntervalTimer = (cb) => {
21
- intervalTimer.current = setInterval(cb, ON_HOLD_INTERVAL);
22
- };
23
-
24
19
  const clearIntervalTimer = () => {
25
20
  try {
26
21
  clearInterval(intervalTimer.current);
@@ -29,6 +24,11 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
29
24
  }
30
25
  };
31
26
 
27
+ const setIntervalTimer = (cb) => {
28
+ clearIntervalTimer();
29
+ intervalTimer.current = setInterval(cb, ON_HOLD_INTERVAL);
30
+ };
31
+
32
32
  const resetState = () => {
33
33
  setIsRunning(false);
34
34
  setDirection(null);
@@ -42,7 +42,7 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
42
42
  if (!player) return;
43
43
 
44
44
  if (direction) {
45
- player[direction](R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
45
+ player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
46
46
  resetHUDTimer();
47
47
  }
48
48
  }, [multiplier, direction]);
@@ -50,7 +50,9 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
50
50
  useEffect(() => {
51
51
  if (isRunning && isRunning !== prevRunning) {
52
52
  setIntervalTimer(() => {
53
- setMultiplier(R.add(1));
53
+ setMultiplier((prev) => {
54
+ return prev + 1;
55
+ });
54
56
  });
55
57
  } else if (!isRunning && isRunning !== prevRunning) {
56
58
  resetState();
@@ -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", () => {
@@ -48,7 +48,11 @@ export function useCellResolver({
48
48
  ...cellResolverOptions
49
49
  }: Props) {
50
50
  let _component = Object.assign({}, component);
51
- const { width, height } = useDimensions("screen");
51
+
52
+ const { width, height } = useDimensions("screen", {
53
+ updateForInactiveScreens: false,
54
+ });
55
+
52
56
  const { plugins, cellStyles } = usePickFromState(["plugins", "cellStyles"]);
53
57
  const isRTL = useIsRTL();
54
58
 
@@ -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
+ };
@@ -5,8 +5,9 @@ import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-co
5
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();
@@ -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
 
@@ -67,7 +67,7 @@ export const useConfiguration = ({
67
67
  if (component) {
68
68
  const remappedStylesConfiguration = remapUpdatedKeys(
69
69
  pluginManifest,
70
- component.styles
70
+ component
71
71
  );
72
72
 
73
73
  R.forEachObjIndexed((value, key) => {
@@ -83,7 +83,7 @@ export const useConfiguration = ({
83
83
 
84
84
  const styles = populateConfigurationValues(
85
85
  pluginManifest?.styles?.fields,
86
- remappedStylesConfiguration,
86
+ remappedStylesConfiguration.styles,
87
87
  skipDefaults
88
88
  );
89
89
 
@@ -108,3 +108,107 @@ export const isAndroidPlatform = () => Platform.OS === "android";
108
108
  export const isTvOSPlatform = () => getPlatform() === "tvos";
109
109
 
110
110
  export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
111
+
112
+ declare global {
113
+ interface Window {
114
+ VIZIO?: {
115
+ Chromevox: {
116
+ play: (text: string) => void;
117
+ };
118
+ exitApplication: () => void;
119
+ setClosedCaptionHandler: (
120
+ callback: (isCCEnabled: boolean) => void
121
+ ) => void;
122
+ };
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Platforms found in userAgent string, please note that simulators
128
+ * might not have the same agents that the devices have
129
+ */
130
+ export const PLATFORMS = {
131
+ webos: "Web0S",
132
+ tizen: "Tizen",
133
+ samsung: "SMART-TV",
134
+ mac: "Mac",
135
+ win: "Win",
136
+ linux: "Linux",
137
+ iphone: "iPhone",
138
+ android: "Android",
139
+ mobile: "Mobile",
140
+ vizio: "VIZIO",
141
+ smartcast: "SmartCast",
142
+ conjure: "Conjure",
143
+ };
144
+
145
+ /**
146
+ * Simple way of identifying if we have access to the tizen APIs
147
+ */
148
+ export const hasTizen = typeof window?.tizen !== "undefined";
149
+
150
+ /**
151
+ * Simple way of identifying if we have access to the webOS APIs
152
+ */
153
+ export const hasWebOS = typeof window?.webOS !== "undefined";
154
+
155
+ export const getUserAgent = () => window?.navigator?.userAgent;
156
+
157
+ export const isLgPlatform = () => {
158
+ const userAgent = getUserAgent();
159
+
160
+ if (!userAgent) {
161
+ return false;
162
+ }
163
+
164
+ // Note: LG uses the number 0 in their userAgent, possibly because of Palm WebOS
165
+ return hasWebOS || userAgent.includes(PLATFORMS.webos);
166
+ };
167
+
168
+ export const isSamsungPlatform = () => {
169
+ const userAgent = getUserAgent();
170
+
171
+ if (!userAgent) {
172
+ return false;
173
+ }
174
+
175
+ return (
176
+ hasTizen ||
177
+ userAgent.includes(PLATFORMS.samsung) ||
178
+ userAgent.includes(PLATFORMS.tizen)
179
+ );
180
+ };
181
+
182
+ /**
183
+ * Checks if we are on the Vizio platform by using the userAgent string
184
+ *
185
+ * Use this method when you need to identify the platform on runtime
186
+ * before the VIZIO Companion Library has loaded
187
+ */
188
+ export const isVizioPlatform = () => {
189
+ const userAgent = getUserAgent();
190
+
191
+ if (!userAgent) {
192
+ return false;
193
+ }
194
+
195
+ const isVizioAgent =
196
+ userAgent.includes(PLATFORMS.vizio) ||
197
+ userAgent.includes(PLATFORMS.smartcast) ||
198
+ userAgent.includes(PLATFORMS.conjure);
199
+
200
+ return isVizioAgent;
201
+ };
202
+
203
+ /**
204
+ * Checks if we are on the Vizio platform by checking for the global VIZIO object
205
+ * and the VIZIO Companion Library. This method does not use the userAgent string,
206
+ * because it mainly checks whether we have access to apis, which may not be available yet
207
+ */
208
+ export const hasVizioAPIs = () => {
209
+ const hasAPIs =
210
+ typeof window.VIZIO !== "undefined" &&
211
+ window?.applicaster?.vizioLibraryDidLoad;
212
+
213
+ return hasAPIs;
214
+ };
@@ -49,11 +49,3 @@ export function useScreenState(
49
49
  setSelectedEntry: (entryId) => setSelectedEntry(screenId, entryId),
50
50
  };
51
51
  }
52
-
53
- export const useScreenScrollStore = create<{
54
- scrollPosition: number;
55
- scrollingVelocity: number;
56
- }>(() => ({
57
- scrollPosition: 0,
58
- scrollingVelocity: 0,
59
- }));