@applicaster/zapp-react-native-utils 12.0.0-alpha.5606245605 → 12.0.0-alpha.5624518702

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 (58) hide show
  1. package/analyticsUtils/AnalyticPlayerListener.ts +155 -0
  2. package/analyticsUtils/AnalyticsEvents/index.ts +6 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
  5. package/analyticsUtils/analyticsPlugins.ts +25 -0
  6. package/analyticsUtils/events.ts +6 -0
  7. package/analyticsUtils/index.tsx +6 -0
  8. package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
  9. package/appUtils/HooksManager/index.js +3 -1
  10. package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +239 -0
  11. package/appUtils/playerManager/conts.ts +5 -0
  12. package/appUtils/playerManager/index.ts +9 -27
  13. package/appUtils/playerManager/player.ts +46 -4
  14. package/appUtils/playerManager/playerFactory.ts +12 -10
  15. package/appUtils/playerManager/playerNative.ts +11 -2
  16. package/appUtils/playerManager/usePlayerControllerSetup.tsx +23 -4
  17. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  18. package/cellUtils/index.ts +10 -14
  19. package/dateUtils/index.ts +11 -0
  20. package/headersUtils/index.ts +1 -0
  21. package/inflatedUrlUtils/index.ts +4 -4
  22. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  23. package/localizationUtils/index.ts +13 -22
  24. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  25. package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
  26. package/manifestUtils/index.js +5 -1
  27. package/manifestUtils/secondaryImage/index.js +18 -15
  28. package/navigationUtils/index.ts +8 -4
  29. package/numberUtils/index.ts +4 -0
  30. package/package.json +2 -2
  31. package/playerUtils/configurationGenerator.ts +3 -1
  32. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  33. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  34. package/reactHooks/cell-click/__tests__/index.test.js +5 -0
  35. package/reactHooks/cell-click/index.ts +2 -2
  36. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  37. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  38. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
  39. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  40. package/reactHooks/layout/types/index.ts +2 -0
  41. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  42. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  43. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  44. package/reactHooks/navigation/__tests__/index.test.tsx +26 -8
  45. package/reactHooks/navigation/index.ts +21 -19
  46. package/reactHooks/player/__tests__/useAutoSeek.test.tsx +8 -1
  47. package/reactHooks/player/useAutoSeek.tsx +23 -7
  48. package/reactHooks/player/useTapSeek.tsx +13 -8
  49. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  50. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  51. package/reactHooks/screen/useScreenContext.ts +5 -4
  52. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  53. package/reactHooks/useListenEventBusEvent.ts +1 -4
  54. package/screenState/index.ts +0 -8
  55. package/stringUtils/index.ts +5 -0
  56. package/testUtils/getByTestId.ts +14 -0
  57. package/testUtils/index.tsx +38 -23
  58. package/types.ts +4 -0
@@ -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
+ }));
@@ -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
 
@@ -45,10 +46,19 @@ const videoItem = {
45
46
  type: { value: "video" },
46
47
  };
47
48
 
49
+ const mockGetStackForPathname = jest.fn().mockReturnValue(homeStack);
50
+
48
51
  const mainStackNavigator = {
49
- getStackForPathname: jest.fn().mockReturnValue(homeStack),
52
+ getStackForPathname: mockGetStackForPathname,
50
53
  getModalState: () => {},
51
54
  videoModalState: {},
55
+ canGoBack: jest.fn(),
56
+ };
57
+
58
+ const _createWrapper = (Wrapper, props) => {
59
+ return function CreatedWrapper({ children }: any) {
60
+ return <Wrapper {...props}>{children}</Wrapper>;
61
+ };
52
62
  };
53
63
 
54
64
  const videoModalNavigator = {
@@ -85,13 +95,21 @@ const store = mockStore({
85
95
  contentTypes,
86
96
  });
87
97
 
88
- const mainStackWrapper = ({ children }) => (
98
+ const mainStackWrapper = ({
99
+ children,
100
+ navigator = {},
101
+ pathname = homeStack.route,
102
+ }) => (
89
103
  <Provider store={store}>
90
- <NavigationContext.Provider value={mainStackNavigator}>
91
- <PathnameContext.Provider value={homeStack.route}>
92
- {children}
93
- </PathnameContext.Provider>
94
- </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>
95
113
  </Provider>
96
114
  );
97
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
 
@@ -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";
@@ -31,6 +31,7 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
31
31
  import { useNavbarState } from "../screen";
32
32
  import { useNavigation } from "./useNavigation";
33
33
  import { useModalStore } from "../../modalState";
34
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
34
35
 
35
36
  export { useNavigation } from "./useNavigation";
36
37
 
@@ -147,6 +148,7 @@ export const useRoute = (): {
147
148
  } => {
148
149
  const pathname = usePathname() || "";
149
150
  const navigator = useNavigation();
151
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
150
152
 
151
153
  const { plugins, contentTypes, rivers } = usePickFromState([
152
154
  "plugins",
@@ -154,7 +156,6 @@ export const useRoute = (): {
154
156
  "contentTypes",
155
157
  ]);
156
158
 
157
- const currentStack = navigator.getStackForPathname(pathname);
158
159
  const { modalState } = useModalStore();
159
160
  const hookModalState = useZappHooksModalState();
160
161
 
@@ -176,15 +177,6 @@ export const useRoute = (): {
176
177
  plugins
177
178
  );
178
179
 
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
180
  // There are 4 route scenarios
189
181
  // For regular screens take date from navigator stack.
190
182
  // is path is model grab screenData from modal state
@@ -211,15 +203,10 @@ export const useRoute = (): {
211
203
  }
212
204
 
213
205
  if (isHookPathname(pathname)) {
214
- const screenData =
215
- "hookPlugin" in currentRouteScreenData
216
- ? currentRouteScreenData
217
- : navigator.screenData;
218
-
219
- return { screenData, pathname };
206
+ return { screenData: screenDataContext, pathname };
220
207
  }
221
208
 
222
- const screenData = currentRouteScreenData;
209
+ const screenData = screenDataContext;
223
210
 
224
211
  return { screenData, pathname };
225
212
  };
@@ -446,3 +433,18 @@ export const useGetBottomTabBarHeight = (): number => {
446
433
 
447
434
  return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
448
435
  };
436
+
437
+ // If current screen is active/focused (visible to the user)
438
+ export const useIsScreenActive = () => {
439
+ const pathname = usePathname();
440
+ const { currentRoute, videoModalState } = useNavigation();
441
+
442
+ if (
443
+ videoModalState.visible &&
444
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
445
+ ) {
446
+ return false;
447
+ }
448
+
449
+ return pathname === currentRoute;
450
+ };
@@ -9,11 +9,18 @@ jest.useFakeTimers();
9
9
 
10
10
  const rewind = jest.fn();
11
11
  const forward = jest.fn();
12
+ const exitDelayedSeek = jest.fn();
13
+ const enterDelayedSeek = jest.fn();
12
14
 
13
15
  jest
14
16
  .spyOn(playerManager, "getInstanceController")
15
17
  // @ts-ignore
16
- .mockImplementation(() => ({ rewind, forward }));
18
+ .mockImplementation(() => ({
19
+ rewind,
20
+ forward,
21
+ exitDelayedSeek,
22
+ enterDelayedSeek,
23
+ }));
17
24
 
18
25
  describe("useAutoSeek", () => {
19
26
  beforeEach(() => {
@@ -14,19 +14,24 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
14
14
  const [isRunning, setIsRunning] = useState<boolean>(false);
15
15
  const [direction, setDirection] = useState<Nullable<SEEK_TYPE>>(null);
16
16
  const [multiplier, setMultiplier] = useState(1);
17
+
17
18
  const intervalTimer = React.useRef(null);
18
19
  const prevRunning = usePrevious(isRunning);
19
20
 
20
21
  const setIntervalTimer = (cb) => {
21
- intervalTimer.current = setInterval(cb, ON_HOLD_INTERVAL);
22
+ if (intervalTimer.current) {
23
+ return;
24
+ }
25
+
26
+ intervalTimer.current = setInterval(() => {
27
+ intervalTimer.current = null;
28
+ cb();
29
+ }, ON_HOLD_INTERVAL);
22
30
  };
23
31
 
24
32
  const clearIntervalTimer = () => {
25
- try {
26
- clearInterval(intervalTimer.current);
27
- } catch (err) {
28
- intervalTimer.current = null;
29
- }
33
+ clearInterval(intervalTimer.current);
34
+ intervalTimer.current = null;
30
35
  };
31
36
 
32
37
  const resetState = () => {
@@ -36,6 +41,17 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
36
41
  clearIntervalTimer();
37
42
  };
38
43
 
44
+ useEffect(() => {
45
+ const player = playerManager.getInstanceController();
46
+ if (!player) return;
47
+
48
+ if (isRunning) {
49
+ player?.enterDelayedSeek();
50
+ } else if (!isRunning) {
51
+ player.exitDelayedSeek();
52
+ }
53
+ }, [isRunning]);
54
+
39
55
  useEffect(() => {
40
56
  const player = playerManager.getInstanceController();
41
57
 
@@ -75,7 +91,7 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
75
91
  setDirection(eventType);
76
92
  setIsRunning(true);
77
93
  },
78
- [isRunning]
94
+ [isRunning, autoSeekStop]
79
95
  );
80
96
 
81
97
  return React.useMemo(
@@ -10,11 +10,8 @@ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
10
10
 
11
11
  type SeekType = SEEK_TYPE | null;
12
12
 
13
- const getSkipTime = (multiplier) => {
14
- const skipTime = R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
15
-
16
- return skipTime;
17
- };
13
+ const getSkipTime = (multiplier) =>
14
+ R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
18
15
 
19
16
  export const useTapSeek = () => {
20
17
  const onPressMultiplier = useRef(1);
@@ -25,7 +22,7 @@ export const useTapSeek = () => {
25
22
  onPressMultiplier.current = 1;
26
23
  }, []);
27
24
 
28
- const handlePressEvent = useCallback(
25
+ return useCallback(
29
26
  (eventType) => {
30
27
  const player = playerManager.getInstanceController();
31
28
  if (!player) return;
@@ -46,13 +43,21 @@ export const useTapSeek = () => {
46
43
  }
47
44
 
48
45
  const seekTime = getSkipTime(onPressMultiplier.current);
46
+
49
47
  player[eventType](seekTime);
50
48
 
49
+ const clicksBeforePause = 3;
50
+
51
+ // Only pause player if user starts to seek on large increments
52
+ if (onPressMultiplier.current > clicksBeforePause) {
53
+ if (!player.isPaused()) {
54
+ player.enterDelayedSeek();
55
+ }
56
+ }
57
+
51
58
  lastPressTime.current = now;
52
59
  currentOnPressEventType.current = eventType;
53
60
  },
54
61
  [resetMultiplier]
55
62
  );
56
-
57
- return handlePressEvent;
58
63
  };
@@ -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 });
@@ -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,9 @@ export function useSetNavbarState() {
44
45
 
45
46
  export function useScreenContext(): NavigationScreenData {
46
47
  const navigator = useNavigation();
48
+ // Cover cases where screenContext is used before navigation is initialized
49
+ const screenData = useContext(ScreenDataContext) || navigator.data;
47
50
 
48
- const screenKey = useMemo(() => navigator?.key, [navigator]);
49
- const screenData = useMemo(() => navigator?.data, [screenKey]);
50
51
  const modalScreenData = navigator?.modalData;
51
52
 
52
53
  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
 
@@ -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 });
@@ -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
- }));
@@ -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
+ }
@@ -0,0 +1,14 @@
1
+ export const getByTestId = (wrapper, testId) => {
2
+ try {
3
+ if (wrapper?.getByTestId) {
4
+ return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
5
+ } else if (wrapper?.root?.findByProps) {
6
+ return wrapper.root.findAllByProps({ testID: testId })?.[0] ?? undefined;
7
+ }
8
+ } catch (e) {
9
+ // eslint-disable-next-line no-console
10
+ console.log("getByTestId E:", e);
11
+
12
+ return undefined;
13
+ }
14
+ };
@@ -1,13 +1,17 @@
1
1
  import * as R from "ramda";
2
2
 
3
- import React from "react";
3
+ import React, { PropsWithChildren } from "react";
4
4
  import { View } from "react-native";
5
5
 
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";
13
+
14
+ export { getByTestId } from "./getByTestId";
11
15
 
12
16
  /**
13
17
  * Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
@@ -19,17 +23,6 @@ import { render } from "@testing-library/react-native";
19
23
  export const testIDEquals = (testId: any): boolean =>
20
24
  R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
21
25
 
22
- export const getByTestId = (wrapper, testId) => {
23
- try {
24
- return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
25
- } catch (e) {
26
- // eslint-disable-next-line no-console
27
- console.log("getByTestId E:", e);
28
-
29
- return undefined;
30
- }
31
- };
32
-
33
26
  /** Helper function for react-test-renderer, accepts type and renderer
34
27
  * * @param {*} type React Component type instance or name of component
35
28
  * * @param {*} renderer renderer instance
@@ -45,11 +38,11 @@ export const findByType = (type, renderer) => {
45
38
  export function createComponentMock(mockName, hasChildren = false) {
46
39
  return hasChildren
47
40
  ? jest.fn(({ children }) => (
48
- <View comp={mockName} testID={mockName}>
41
+ <View testID={mockName}>
49
42
  {typeof children === "function" ? children() : children}
50
43
  </View>
51
44
  ))
52
- : jest.fn(() => <View comp={mockName} testID={mockName} />);
45
+ : jest.fn(() => <View testID={mockName} />);
53
46
  }
54
47
 
55
48
  const initialState = {
@@ -62,16 +55,34 @@ const initialState = {
62
55
  AppContainer: createComponentMock("appContainer", true),
63
56
  DisplayError: createComponentMock("displayError"),
64
57
  },
65
- rivers: [{ id: "A1234", home: true }],
58
+ rivers: { id: "A1234", home: true },
66
59
  appSettings: {},
67
60
  plugins: [],
68
- appState: { appReady: true },
61
+ appState: { appReady: true, appLaunched: true },
62
+ appData: { layoutVersion: "v1" },
63
+ contentTypes: null,
69
64
  };
70
65
 
71
- export const WrappedWithProviders = ({ children, store = {} }: any) => {
72
- const _store = configureStore([thunk])({ ...initialState, store });
66
+ export const WrappedWithProviders = ({
67
+ children,
68
+ store: storeObj = {},
69
+ }: any) => {
70
+ const _store = configureStore([thunk])(
71
+ R.mergeDeepWith(R.concat, { ...initialState }, storeObj)
72
+ );
73
73
 
74
- return <Provider store={_store}>{children}</Provider>;
74
+ return (
75
+ <SafeAreaProvider
76
+ initialMetrics={{
77
+ insets: { top: 0, left: 0, right: 0, bottom: 0 },
78
+ frame: { x: 0, y: 0, width: 0, height: 0 },
79
+ }}
80
+ >
81
+ <Provider store={_store}>
82
+ <AnalyticsProvider>{children}</AnalyticsProvider>
83
+ </Provider>
84
+ </SafeAreaProvider>
85
+ );
75
86
  };
76
87
 
77
88
  /**
@@ -80,8 +91,12 @@ export const WrappedWithProviders = ({ children, store = {} }: any) => {
80
91
  * @param store optional store to pass to the provider
81
92
  * @returns
82
93
  */
83
- export const renderWithProviders = (component, store?: unknown) => {
84
- return render(
85
- <WrappedWithProviders store={store}>{component}</WrappedWithProviders>
86
- );
94
+ export const renderWithProviders = (component, storeObj?: unknown) => {
95
+ return render(component, {
96
+ wrapper: function TestWrapper({ children }: PropsWithChildren<any>) {
97
+ return (
98
+ <WrappedWithProviders store={storeObj}>{children}</WrappedWithProviders>
99
+ );
100
+ },
101
+ });
87
102
  };
package/types.ts CHANGED
@@ -5,3 +5,7 @@ export type ManifestField<T> = {
5
5
  group?: boolean;
6
6
  fields?: ManifestField<any>[];
7
7
  };
8
+
9
+ export enum ENDPOINT_TAGS {
10
+ allow_missing_keys = "allow_missing_keys",
11
+ }