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

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 (47) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +16 -8
  2. package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
  3. package/analyticsUtils/helpers/hooks.ts +1 -1
  4. package/appUtils/focusManager/treeDataStructure/Utils/index.js +12 -3
  5. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
  6. package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
  7. package/appUtils/keyCodes/keys.web.js +1 -0
  8. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
  9. package/appUtils/playerManager/player.ts +12 -4
  10. package/appUtils/playerManager/playerNative.ts +26 -0
  11. package/appUtils/playerManager/usePlayerState.tsx +13 -1
  12. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
  13. package/cellUtils/__tests__/cellUtils.test.ts +59 -0
  14. package/cellUtils/__tests__/fixtures.ts +13 -0
  15. package/cellUtils/index.ts +29 -0
  16. package/focusManager/index.ts +1 -1
  17. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
  18. package/functionUtils/__tests__/functionUtils.test.js +244 -248
  19. package/localizationUtils/__tests__/localizationUtils.test.ts +17 -13
  20. package/localizationUtils/index.ts +6 -3
  21. package/logger/index.ts +1 -1
  22. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  23. package/modalState/index.ts +57 -0
  24. package/navigationUtils/index.ts +56 -7
  25. package/package.json +3 -2
  26. package/playerUtils/configurationGenerator.ts +8 -0
  27. package/pluginUtils/index.ts +2 -2
  28. package/reactHooks/cell-click/__tests__/index.test.js +6 -2
  29. package/reactHooks/cell-click/index.ts +2 -2
  30. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
  31. package/reactHooks/index.ts +2 -0
  32. package/reactHooks/layout/__tests__/index.test.js +22 -30
  33. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
  34. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
  35. package/reactHooks/navigation/__mocks__/useNavigation.ts +4 -0
  36. package/reactHooks/navigation/__tests__/index.test.tsx +234 -78
  37. package/reactHooks/navigation/index.ts +201 -85
  38. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  39. package/reactHooks/screen/index.ts +2 -0
  40. package/reactHooks/screen/useScreenContext.ts +1 -1
  41. package/reactHooks/screen/useScreenData.ts +1 -1
  42. package/reactHooks/state/useRivers.ts +3 -1
  43. package/reactHooks/useListenEventBusEvent.ts +1 -4
  44. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
  45. package/riverComponetsMeasurementProvider/index.tsx +2 -2
  46. package/screenState/index.ts +8 -0
  47. package/testUtils/index.tsx +15 -2
@@ -17,18 +17,103 @@ import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-component
17
17
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
18
18
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
19
19
  import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
20
- import { getNavigationProps } from "@applicaster/zapp-react-native-utils/navigationUtils";
21
20
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
22
- import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
21
+ import {
22
+ getRiverFromRoute,
23
+ getTargetRoute,
24
+ getNavigationProps,
25
+ } from "../../navigationUtils";
23
26
  import { platformSelect } from "../../reactUtils";
24
27
  import { useConnectionInfo } from "../connection";
25
28
  import { getTargetScreenData } from "../screen/useTargetScreenData";
26
- import { useNavbarState } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
27
29
 
30
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
31
+ import { useNavbarState } from "../screen";
28
32
  import { useNavigation } from "./useNavigation";
33
+ import { useModalStore } from "../../modalState";
29
34
 
30
35
  export { useNavigation } from "./useNavigation";
31
36
 
37
+ /**
38
+ * This function helps to decide wether the navbar should be presented on the screen
39
+ * based on route and / or screen Data
40
+ *
41
+ * Currently the scenarios include
42
+ * - players => false
43
+ * - search screen plugin => false
44
+ * - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
45
+ * - screens with `allow_screen_plugin_presentation` in general property => false
46
+ *
47
+ * @param {String} route current route of the screen
48
+ * @param {Object} screenData payload associated with the currently presented screen
49
+ * @returns {Boolean}
50
+ */
51
+ export function isNavBarVisible(
52
+ route: string,
53
+ screenData: ZappRiver = {} as ZappRiver,
54
+ showNavBar: boolean,
55
+ canGoBack: boolean,
56
+ videoModalState: QuickBrickVideoModalState | null = null
57
+ ) {
58
+ /* screenData is not actual navigator.data
59
+ * or navigator.screenData,
60
+ * but navigator.data.screen */
61
+ if (route.includes("playable")) {
62
+ return false;
63
+ }
64
+
65
+ if (
66
+ videoModalState?.mode === "FULLSCREEN" &&
67
+ videoModalState?.visible === true
68
+ ) {
69
+ return false;
70
+ }
71
+
72
+ if (screenData?.type === "qb_search_screen" && !isTV()) {
73
+ return false;
74
+ }
75
+
76
+ /* Match if screen is Hook */
77
+ if (route.startsWith("/hooks/")) {
78
+ const module = screenData?.module;
79
+
80
+ if (module?.presentFullScreen) {
81
+ return false;
82
+ }
83
+
84
+ return module?.showNavBar ?? false;
85
+ }
86
+
87
+ if (screenData?.hookPlugin) {
88
+ const hookPlugin = screenData?.hookPlugin?.module;
89
+
90
+ return (
91
+ hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
92
+ );
93
+ }
94
+
95
+ if (
96
+ screenData?.general?.allow_screen_plugin_presentation ||
97
+ screenData?.general?.hide_app_nav_bar
98
+ ) {
99
+ return false;
100
+ }
101
+
102
+ const hideSecondaryLevel = screenData?.navigations?.some(
103
+ (navigation) => navigation.styles?.hide_secondary_level_menu
104
+ );
105
+
106
+ if (canGoBack && hideSecondaryLevel) {
107
+ return false;
108
+ }
109
+
110
+ if (typeof showNavBar === "boolean" && !showNavBar) {
111
+ return false;
112
+ }
113
+
114
+ return true;
115
+ }
116
+
32
117
  const { ProfilerBridge } = NativeModules;
33
118
 
34
119
  export const usePathname = () => React.useContext(PathnameContext);
@@ -43,6 +128,102 @@ export const useBackHandler = (cb: () => boolean) => {
43
128
  }, [cb]);
44
129
  };
45
130
 
131
+ // starts with modal/
132
+ const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
133
+
134
+ const isVideoModalPathname = (pathname: string) =>
135
+ /^video-modal\//.test(pathname);
136
+
137
+ const isHookModalPathname = (pathname: string) =>
138
+ /^hooks-modal\//.test(pathname);
139
+
140
+ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
141
+
142
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
143
+
144
+ export const useRoute = (): {
145
+ screenData: VariousScreenData;
146
+ pathname: string;
147
+ } => {
148
+ const pathname = usePathname() || "";
149
+ const navigator = useNavigation();
150
+
151
+ const { plugins, contentTypes, rivers } = usePickFromState([
152
+ "plugins",
153
+ "rivers",
154
+ "contentTypes",
155
+ ]);
156
+
157
+ const currentStack = navigator.getStackForPathname(pathname);
158
+ const { modalState } = useModalStore();
159
+ const hookModalState = useZappHooksModalState();
160
+
161
+ const modalScreenData = modalState.screen;
162
+
163
+ const hookModalScreenData = hookModalState.state.screenData?.payload;
164
+
165
+ const videoModalScreenData =
166
+ navigator.videoModalState?.item &&
167
+ legacyScreenData(
168
+ {
169
+ entry: navigator.videoModalState?.item as ZappEntry,
170
+ screen: getTargetScreenData(
171
+ navigator.videoModalState?.item as ZappEntry,
172
+ rivers,
173
+ contentTypes
174
+ ),
175
+ },
176
+ plugins
177
+ );
178
+
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
+ // There are 4 route scenarios
189
+ // For regular screens take date from navigator stack.
190
+ // is path is model grab screenData from modal state
191
+ // if path is video modal grab screenData from video state
192
+ // if path is hook modal grab screenData from hook state
193
+ // if path is hook grab screenData from screenData
194
+
195
+ if (isModalPathname(pathname)) {
196
+ const screenData = modalScreenData ?? ({} as ZappEntry);
197
+
198
+ return { screenData, pathname };
199
+ }
200
+
201
+ if (isVideoModalPathname(pathname)) {
202
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
203
+
204
+ return { screenData, pathname };
205
+ }
206
+
207
+ if (isHookModalPathname(pathname)) {
208
+ const screenData = hookModalScreenData;
209
+
210
+ return { screenData, pathname };
211
+ }
212
+
213
+ if (isHookPathname(pathname)) {
214
+ const screenData =
215
+ "hookPlugin" in currentRouteScreenData
216
+ ? currentRouteScreenData
217
+ : navigator.screenData;
218
+
219
+ return { screenData, pathname };
220
+ }
221
+
222
+ const screenData = currentRouteScreenData;
223
+
224
+ return { screenData, pathname };
225
+ };
226
+
46
227
  type Callbacks = Partial<{
47
228
  handleHookPresent: ({
48
229
  route,
@@ -209,7 +390,7 @@ export const useRunIfLongPress = (
209
390
  React.useRef<Nullable<ReturnType<typeof setTimeout>>>(null);
210
391
 
211
392
  const resetTimeout = () => {
212
- clearTimeout(pressTimeout.current);
393
+ clearTimeout(pressTimeout.current as ReturnType<typeof setTimeout>);
213
394
  };
214
395
 
215
396
  const startTimeout = (cb: () => void) => {
@@ -231,82 +412,12 @@ export const useRunIfLongPress = (
231
412
  * @returns boolean - navbar visiblity status
232
413
  */
233
414
  export const useIsNavBarVisible = (): boolean => {
234
- const visible = useNavbarState().visible;
415
+ const { visible } = useNavbarState();
235
416
 
236
417
  return useMemo(() => visible, [visible]);
237
418
  };
238
419
 
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() || "";
249
- const navigator = useNavigation();
250
-
251
- const { plugins, contentTypes, rivers } = usePickFromState([
252
- "plugins",
253
- "rivers",
254
- "contentTypes",
255
- ]);
256
-
257
- const currentStack = navigator.getStackForPathname(pathname);
258
- const modalState = navigator.modalState;
259
- const hookModalState = useZappHooksModalState();
260
-
261
- const modalScreenData = modalState.screen;
262
-
263
- const hookModalScreenData = hookModalState.state.screenData?.payload;
264
-
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
- );
278
-
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
- },
287
-
288
- plugins
289
- );
290
-
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
296
-
297
- const screenData = isModalPathname(pathname)
298
- ? modalScreenData
299
- : isVideoModalPathname(pathname)
300
- ? videoModalScreenData
301
- : isHookModalPathname(pathname)
302
- ? hookModalScreenData
303
- : currentRouteScreenData;
304
-
305
- return { screenData, pathname };
306
- };
307
-
308
- export const useGetBottomTabBarHeight = (): number => {
309
- const insets = useSafeAreaInsets();
420
+ const useGetNavBarTopBorderWidth = (): number => {
310
421
  const navigator = useNavigation();
311
422
 
312
423
  const navProps = getNavigationProps({
@@ -315,18 +426,23 @@ export const useGetBottomTabBarHeight = (): number => {
315
426
  category: "menu",
316
427
  });
317
428
 
318
- const navType = useNavigationType();
319
- const isBottomBarNavigation = navType === MenuTypes.bottomTabBar;
320
-
321
- const TAB_BAR_HEIGHT_IOS = 49;
322
- const TAB_BAR_HEIGHT_ANDROID = 56;
429
+ return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
430
+ };
323
431
 
324
- if (!isBottomBarNavigation) return 0;
432
+ const TAB_BAR_HEIGHT_IOS = 49;
433
+ const TAB_BAR_HEIGHT_ANDROID = 56;
325
434
 
326
- const tabBarHeight = platformSelect({
327
- ios: TAB_BAR_HEIGHT_IOS + insets.bottom,
435
+ const useGetTabBarHeight = () =>
436
+ platformSelect({
437
+ ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
328
438
  android: TAB_BAR_HEIGHT_ANDROID,
329
439
  }) as number;
330
440
 
331
- return tabBarHeight + Number(navProps?.styles?.top_border_width ?? 0);
441
+ export const useGetBottomTabBarHeight = (): number => {
442
+ const topBorderWidth = useGetNavBarTopBorderWidth();
443
+ const tabBarHeight = useGetTabBarHeight();
444
+
445
+ const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
446
+
447
+ return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
332
448
  };
@@ -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 });
@@ -2,6 +2,8 @@ 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,
@@ -2,7 +2,7 @@ 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
8
 
@@ -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,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(
@@ -49,3 +49,11 @@ 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
+ }));
@@ -6,8 +6,10 @@ import { View } from "react-native";
6
6
  import { Provider } from "react-redux";
7
7
  import thunk from "redux-thunk";
8
8
  import configureStore from "redux-mock-store";
9
+ import { SafeAreaProvider } from "react-native-safe-area-context";
9
10
 
10
11
  import { render } from "@testing-library/react-native";
12
+ import { AnalyticsProvider } from "../analyticsUtils";
11
13
 
12
14
  /**
13
15
  * Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
@@ -69,9 +71,20 @@ const initialState = {
69
71
  };
70
72
 
71
73
  export const WrappedWithProviders = ({ children, store = {} }: any) => {
72
- const _store = configureStore([thunk])({ ...initialState, store });
74
+ const _store = configureStore([thunk])({ ...initialState, ...store });
73
75
 
74
- return <Provider store={_store}>{children}</Provider>;
76
+ return (
77
+ <SafeAreaProvider
78
+ initialMetrics={{
79
+ insets: { top: 0, left: 0, right: 0, bottom: 0 },
80
+ frame: { x: 0, y: 0, width: 0, height: 0 },
81
+ }}
82
+ >
83
+ <Provider store={_store}>
84
+ <AnalyticsProvider>{children}</AnalyticsProvider>
85
+ </Provider>
86
+ </SafeAreaProvider>
87
+ );
75
88
  };
76
89
 
77
90
  /**