@applicaster/zapp-react-native-utils 14.0.0-alpha.3126393935 → 14.0.0-alpha.3216572828

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 (68) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +83 -60
  2. package/analyticsUtils/AnalyticsEvents/helper.ts +1 -1
  3. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  4. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  5. package/analyticsUtils/index.tsx +3 -4
  6. package/analyticsUtils/manager.ts +1 -1
  7. package/appUtils/HooksManager/Hook.ts +4 -4
  8. package/appUtils/HooksManager/index.ts +11 -1
  9. package/appUtils/accessibilityManager/index.ts +3 -3
  10. package/appUtils/contextKeysManager/contextResolver.ts +1 -14
  11. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +5 -0
  12. package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
  13. package/appUtils/focusManager/index.ios.ts +10 -0
  14. package/appUtils/focusManager/index.ts +82 -11
  15. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  16. package/appUtils/focusManagerAux/utils/index.ts +106 -3
  17. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
  18. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  19. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  20. package/arrayUtils/index.ts +1 -1
  21. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  22. package/componentsUtils/index.ts +4 -1
  23. package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
  24. package/configurationUtils/manifestKeyParser.ts +57 -32
  25. package/index.d.ts +0 -9
  26. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  27. package/navigationUtils/index.ts +6 -4
  28. package/package.json +2 -3
  29. package/playerUtils/index.ts +51 -0
  30. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  31. package/reactHooks/cell-click/index.ts +1 -8
  32. package/reactHooks/debugging/__tests__/index.test.js +0 -1
  33. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
  34. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
  35. package/reactHooks/feed/useBatchLoading.ts +8 -6
  36. package/reactHooks/feed/useFeedLoader.tsx +14 -17
  37. package/reactHooks/feed/usePipesCacheReset.ts +2 -2
  38. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  39. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  40. package/reactHooks/layout/isTablet/index.ts +12 -5
  41. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  42. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  43. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  44. package/reactHooks/navigation/index.ts +7 -5
  45. package/reactHooks/navigation/useRoute.ts +2 -7
  46. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  47. package/reactHooks/state/index.ts +1 -1
  48. package/reactHooks/state/useHomeRiver.ts +4 -2
  49. package/reactHooks/state/useRivers.ts +7 -8
  50. package/screenPickerUtils/index.ts +7 -0
  51. package/testUtils/index.tsx +7 -8
  52. package/time/BackgroundTimer.ts +1 -1
  53. package/utils/__tests__/find.test.ts +36 -0
  54. package/utils/__tests__/pathOr.test.ts +37 -0
  55. package/utils/__tests__/startsWith.test.ts +30 -0
  56. package/utils/find.ts +3 -0
  57. package/utils/index.ts +8 -0
  58. package/utils/pathOr.ts +5 -0
  59. package/utils/startsWith.ts +9 -0
  60. package/actionsExecutor/ScreenActions.ts +0 -163
  61. package/actionsExecutor/StorageActions.ts +0 -110
  62. package/actionsExecutor/feedDecorator.ts +0 -171
  63. package/actionsExecutor/screenResolver.ts +0 -11
  64. package/reactHooks/navigation/useScreenStateStore.ts +0 -8
  65. package/storage/ScreenSingleValueProvider.ts +0 -201
  66. package/storage/ScreenStateMultiSelectProvider.ts +0 -290
  67. package/storage/StorageMultiSelectProvider.ts +0 -192
  68. package/storage/StorageSingleSelectProvider.ts +0 -108
@@ -1,8 +1,10 @@
1
1
  import { complement, compose, isNil, map, min, prop, take, uniq } from "ramda";
2
- import { useDispatch } from "react-redux";
3
2
  import * as React from "react";
4
- import { useZappPipesFeeds } from "@applicaster/zapp-react-native-redux/hooks";
5
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
3
+ import {
4
+ ZappPipes,
5
+ useAppDispatch,
6
+ useZappPipesFeed,
7
+ } from "@applicaster/zapp-react-native-redux";
6
8
  import { isNilOrEmpty } from "../../reactUtils/helpers";
7
9
  import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
8
10
  import {
@@ -63,7 +65,7 @@ export const useBatchLoading = (
63
65
  componentsToRender: { data?: ZappDataSource; component_type: string }[],
64
66
  options: Options
65
67
  ) => {
66
- const dispatch = useDispatch();
68
+ const dispatch = useAppDispatch();
67
69
  const { screen: screenContext, entry: entryContext } = useScreenContext();
68
70
  const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
69
71
  const [hasEverBeenReady, setHasEverBeenReady] = React.useState(false);
@@ -118,7 +120,7 @@ export const useBatchLoading = (
118
120
  []
119
121
  );
120
122
 
121
- const feeds = useZappPipesFeeds(feedUrls);
123
+ const feeds = useZappPipesFeed(feedUrls);
122
124
 
123
125
  // dispatch loadPipesData for each feed that is not loaded
124
126
  const runBatchLoading = React.useCallback(() => {
@@ -139,7 +141,7 @@ export const useBatchLoading = (
139
141
  if (mappedFeedUrl) {
140
142
  // 4. load data
141
143
  return dispatch(
142
- loadPipesData(mappedFeedUrl, { riverId: options.riverId })
144
+ ZappPipes.loadPipesData(mappedFeedUrl, { riverId: options.riverId })
143
145
  );
144
146
  }
145
147
  }
@@ -1,14 +1,15 @@
1
1
  import React, { useEffect } from "react";
2
- import { useDispatch } from "react-redux";
3
2
 
4
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
- import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux/hooks";
3
+ import {
4
+ ZappPipes,
5
+ useAppDispatch,
6
+ useZappPipesFeed,
7
+ } from "@applicaster/zapp-react-native-redux";
6
8
 
7
9
  import { reactHooksLogger } from "../logger";
8
10
  import { shouldDispatchData, useIsInitialRender } from "../utils";
9
11
  import { useInflatedUrl } from "./useInflatedUrl";
10
12
  import { useRoute } from "../navigation";
11
- import { useScreenResolvers } from "@applicaster/zapp-react-native-utils/actionsExecutor/screenResolver";
12
13
 
13
14
  const logger = reactHooksLogger.addSubsystem("useFeedLoader");
14
15
 
@@ -50,9 +51,8 @@ export const useFeedLoader = ({
50
51
  }, []);
51
52
 
52
53
  const isInitialRender = useIsInitialRender();
53
- const dispatch = useDispatch();
54
+ const dispatch = useAppDispatch();
54
55
  const { screenData } = useRoute();
55
- const resolvers = useScreenResolvers();
56
56
 
57
57
  const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
58
58
 
@@ -66,17 +66,16 @@ export const useFeedLoader = ({
66
66
  (silentRefresh = true, callback) => {
67
67
  if (callableFeedUrl) {
68
68
  dispatch(
69
- loadPipesData(callableFeedUrl, {
69
+ ZappPipes.loadPipesData(callableFeedUrl, {
70
70
  clearCache: true,
71
71
  silentRefresh,
72
72
  callback,
73
73
  riverId,
74
- resolvers,
75
74
  })
76
75
  );
77
76
  }
78
77
  },
79
- [callableFeedUrl, resolvers]
78
+ [callableFeedUrl]
80
79
  );
81
80
 
82
81
  const loadNext: FeedLoaderResponse["loadNext"] = React.useCallback(() => {
@@ -85,16 +84,15 @@ export const useFeedLoader = ({
85
84
 
86
85
  if (nextFeed) {
87
86
  dispatch(
88
- loadPipesData(nextFeed, {
87
+ ZappPipes.loadPipesData(nextFeed, {
89
88
  silentRefresh: true,
90
89
  parentFeed: callableFeedUrl,
91
90
  riverId,
92
- resolvers,
93
91
  })
94
92
  );
95
93
  }
96
94
  }
97
- }, [callableFeedUrl, currentFeed?.data?.next, resolvers]);
95
+ }, [callableFeedUrl, currentFeed?.data?.next]);
98
96
 
99
97
  useEffect(() => {
100
98
  if (
@@ -102,11 +100,10 @@ export const useFeedLoader = ({
102
100
  ) {
103
101
  if (callableFeedUrl && !pipesOptions.skipLoading) {
104
102
  dispatch(
105
- loadPipesData(callableFeedUrl, {
103
+ ZappPipes.loadPipesData(callableFeedUrl, {
106
104
  ...pipesOptions,
107
105
  clearCache: true,
108
106
  riverId,
109
- resolvers,
110
107
  })
111
108
  );
112
109
  } else if (!callableFeedUrl) {
@@ -131,16 +128,16 @@ export const useFeedLoader = ({
131
128
  jsOnly: true,
132
129
  });
133
130
  }
134
- }, [resolvers]);
131
+ }, []);
135
132
 
136
133
  // Reload feed when feedUrl changes, unless skipLoading is true
137
134
  useEffect(() => {
138
135
  if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
139
136
  dispatch(
140
- loadPipesData(callableFeedUrl, { ...pipesOptions, riverId, resolvers })
137
+ ZappPipes.loadPipesData(callableFeedUrl, { ...pipesOptions, riverId })
141
138
  );
142
139
  }
143
- }, [callableFeedUrl, resolvers]);
140
+ }, [callableFeedUrl]);
144
141
 
145
142
  return React.useMemo(() => {
146
143
  if (!callableFeedUrl || !feedUrl) {
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
- import { useDispatch } from "react-redux";
3
2
 
4
3
  import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
5
4
  import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
6
5
  import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
7
6
 
8
7
  import { useRoute } from "../navigation";
8
+ import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
9
9
 
10
10
  /**
11
11
  * reset river components cache when screen is unmounted
@@ -13,7 +13,7 @@ import { useRoute } from "../navigation";
13
13
  * @param {Array} riverComponents list of UI components
14
14
  */
15
15
  export const usePipesCacheReset = (riverId, riverComponents) => {
16
- const dispatch = useDispatch();
16
+ const dispatch = useAppDispatch();
17
17
  const { screenData, pathname } = useRoute();
18
18
  const pipesContexts = usePipesContexts(riverId, pathname);
19
19
 
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import * as R from "ramda";
3
- import { View } from "react-native";
3
+ import { View, ViewStyle } from "react-native";
4
4
 
5
5
  import { platformSelect } from "../../reactUtils";
6
6
 
@@ -49,13 +49,13 @@ export const useSequentialRenderItem = (data: Data) => {
49
49
  const readyToDisplay =
50
50
  index === 0 ? true : arePreviousComponentsReady(index);
51
51
 
52
- const displayStyle = {
52
+ const displayStyle: ViewStyle = {
53
53
  display: readyToDisplay ? "flex" : "none",
54
54
  };
55
55
 
56
56
  const readyStyle = {
57
57
  visibility: readyToDisplay ? "visible" : "hidden",
58
- };
58
+ } as ViewStyle;
59
59
 
60
60
  const style = platformSelect({
61
61
  tvos: readyStyle,
@@ -42,15 +42,17 @@ jest.mock("react-native-safe-area-context", () => ({
42
42
  }));
43
43
 
44
44
  jest.mock("../../../reactUtils", () => ({
45
+ ...jest.requireActual("../../../reactUtils"),
45
46
  platformSelect: jest.fn((specs) => specs[platform] || specs.default),
46
47
  isTV: jest.fn(() => mock_tv_flag),
47
48
  }));
48
49
 
49
50
  jest.mock("../../navigation", () => ({
50
- useNavigation: () => null,
51
51
  useIsScreenActive: () => true,
52
52
  }));
53
53
 
54
+ jest.mock("../../navigation/useNavigation");
55
+
54
56
  const { Dimensions } = require("react-native");
55
57
  const { useDimensions } = require("..");
56
58
 
@@ -1,21 +1,28 @@
1
1
  import { NativeModules, Platform } from "react-native";
2
2
 
3
+ export const isAndroidTablet = () => {
4
+ const { initialProps } = NativeModules.QuickBrickCommunicationModule;
5
+
6
+ return initialProps?.is_tablet;
7
+ };
8
+
3
9
  /**
4
10
  * Determines wether the given device is a tablet based on dimensions, orientation, and platform
5
11
  * @param {Object} dimensions - Dimensions object passed to the function
6
12
  * @param {String} orientation - Orientation enum passed to the function
7
13
  * @returns {Boolean} isTablet - returns whether the given device is a tablet
8
14
  */
9
- export const isTablet = (dimensions, orientation) => {
15
+ export const isTablet = (
16
+ dimensions?: { width: number; height: number },
17
+ orientation?: string
18
+ ) => {
10
19
  if (Platform?.OS === "ios") {
11
20
  return Platform?.isPad;
12
21
  } else if (Platform?.OS === "android") {
13
- const { initialProps } = NativeModules.QuickBrickCommunicationModule;
14
-
15
- return initialProps?.is_tablet;
22
+ return isAndroidTablet();
16
23
  }
17
24
 
18
- const { width } = dimensions;
25
+ const { width } = dimensions || {};
19
26
 
20
27
  if (width < 600) return false;
21
28
  if (width >= 600 && width < 840) return orientation === "portrait";
@@ -1,46 +1,48 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
2
  import { Dimensions, StatusBar } from "react-native";
3
+ import { useDimensions } from "../useDimensions";
4
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux";
3
5
 
4
- const mockUsePickFromState = jest.fn();
5
- const mockUseIsScreenActive = jest.fn();
6
- const mockGetInitialDimensions = jest.fn();
7
- const mockGetDeviceInfo = jest.fn();
6
+ import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
8
7
 
9
- jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
10
- ...(jest.requireActual("@applicaster/zapp-react-native-redux/hooks") as {}),
11
- usePickFromState: mockUsePickFromState,
12
- }));
13
-
14
- jest.mock("../../../navigation", () => ({
15
- useIsScreenActive: mockUseIsScreenActive,
16
- }));
8
+ jest.mock("@applicaster/zapp-react-native-redux/hooks", () => {
9
+ return {
10
+ ...jest.requireActual("@applicaster/zapp-react-native-redux/hooks"),
11
+ usePickFromState: jest.fn(),
12
+ };
13
+ });
17
14
 
18
- jest.mock("../helpers", () => ({
19
- getInitialDimensions: mockGetInitialDimensions,
15
+ jest.mock(
16
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive",
17
+ () => ({
18
+ useIsScreenActive: jest.fn().mockReturnValue(true),
19
+ })
20
+ );
21
+
22
+ jest.doMock("../helpers", () => ({
23
+ getInitialDimensions: jest
24
+ .fn()
25
+ .mockReturnValue({ width: 100, height: 200, scale: 1, fontScale: 1 }),
20
26
  }));
21
27
 
22
28
  jest.mock("../../getDeviceInfo", () => ({
23
- getDeviceInfo: mockGetDeviceInfo,
29
+ getDeviceInfo: jest.fn().mockReturnValue({ deviceInfo: "testDeviceInfo" }),
24
30
  }));
25
31
 
26
- const { useDimensions } = require("../useDimensions");
32
+ const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
33
+
34
+ Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
35
+
36
+ Dimensions.addEventListener = jest.fn().mockReturnValue({
37
+ remove: jest.fn(),
38
+ });
27
39
 
28
40
  describe("useDimensions", () => {
29
- const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
30
41
  const mockAppData = { someData: "test" };
31
42
 
32
43
  beforeEach(() => {
33
- jest.clearAllMocks();
34
- Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
35
-
36
- Dimensions.addEventListener = jest.fn().mockReturnValue({
37
- remove: jest.fn(),
38
- });
39
-
40
- mockUsePickFromState.mockReturnValue({ appData: mockAppData });
41
- mockUseIsScreenActive.mockReturnValue(true);
42
- mockGetInitialDimensions.mockReturnValue(mockDimensions);
43
- mockGetDeviceInfo.mockReturnValue({ deviceInfo: "testDeviceInfo" });
44
+ StatusBar.currentHeight = 20;
45
+ (usePickFromState as jest.Mock).mockReturnValue({ appData: mockAppData });
44
46
  });
45
47
 
46
48
  it("returns correct initial dimensions", () => {
@@ -48,12 +50,9 @@ describe("useDimensions", () => {
48
50
  useDimensions("window", { fullDimensions: false })
49
51
  );
50
52
 
51
- expect(result.current).toEqual({
52
- ...mockDimensions,
53
+ expect(result.current).toMatchObject({
53
54
  statusBarHeight: StatusBar.currentHeight,
54
55
  });
55
-
56
- expect(mockGetInitialDimensions).toHaveBeenCalledWith("window");
57
56
  });
58
57
 
59
58
  it("calls handler on mount", () => {
@@ -70,7 +69,7 @@ describe("useDimensions", () => {
70
69
  useDimensions("window", { fullDimensions: false })
71
70
  );
72
71
 
73
- mockUseIsScreenActive.mockReturnValue(false);
72
+ (useIsScreenActive as jest.Mock).mockReturnValue(false);
74
73
  rerender();
75
74
 
76
75
  expect(Dimensions.addEventListener).toHaveBeenCalledWith(
@@ -84,8 +83,7 @@ describe("useDimensions", () => {
84
83
  useDimensions("window", { fullDimensions: true })
85
84
  );
86
85
 
87
- expect(result.current).toEqual({
88
- ...mockDimensions,
86
+ expect(result.current).toMatchObject({
89
87
  scale: 1,
90
88
  fontScale: 1,
91
89
  statusBarHeight: StatusBar.currentHeight,
@@ -98,7 +96,7 @@ describe("useDimensions", () => {
98
96
  );
99
97
 
100
98
  expect(result.current.height).toBe(
101
- mockDimensions.height - StatusBar.currentHeight ?? 0
99
+ mockDimensions.height - (StatusBar?.currentHeight ?? 0)
102
100
  );
103
101
  });
104
102
 
@@ -10,7 +10,7 @@ import { isTV } from "../../../reactUtils";
10
10
  import { Options, UseDimensions } from "../types";
11
11
  import { getDeviceInfo } from "../getDeviceInfo";
12
12
  import { getInitialDimensions } from "./helpers";
13
- import { useIsScreenActive } from "../../navigation";
13
+ import { useIsScreenActive } from "../../navigation/useIsScreenActive";
14
14
 
15
15
  function compensateForScaleIfNeeded(context) {
16
16
  return function () {
@@ -24,8 +24,6 @@ const applyScaleToDimensions = R.unless(R.propEq("scale", 1), (dimensions) => ({
24
24
  scale: 1,
25
25
  }));
26
26
 
27
- const statusBarHeight = StatusBar?.currentHeight;
28
-
29
27
  /**
30
28
  * Returns React-native Dimensions object and updates it on any dimension change
31
29
  * @param {('screen'|'window')} [context=window] - Dimensions context passed to Dimensions.get method
@@ -37,6 +35,7 @@ export const useDimensions: UseDimensions = (
37
35
  context = "window",
38
36
  fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
39
37
  ) => {
38
+ const statusBarHeight = StatusBar?.currentHeight;
40
39
  const isActive = useIsScreenActive();
41
40
  const { appData } = usePickFromState(["appData"]);
42
41
 
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable no-redeclare */
2
- import { useSelector } from "react-redux";
3
- import * as R from "ramda";
2
+ import {
3
+ useAppSelector,
4
+ selectLayoutVersion,
5
+ } from "@applicaster/zapp-react-native-redux";
4
6
 
5
7
  export function useLayoutVersion(): ZappLayoutVersions;
6
8
 
@@ -23,9 +25,7 @@ export function useLayoutVersion({
23
25
  isV2?: boolean;
24
26
  isV1?: boolean;
25
27
  } = {}): boolean | ZappLayoutVersions {
26
- const layoutVersion = useSelector<any, ZappLayoutVersions>(
27
- R.path(["appData", "layoutVersion"])
28
- );
28
+ const layoutVersion = useAppSelector(selectLayoutVersion);
29
29
 
30
30
  if (isV2) {
31
31
  return layoutVersion === "v2";
@@ -14,7 +14,7 @@ import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
14
14
  import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
15
15
  import { useConnectionInfo } from "../connection";
16
16
 
17
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
17
+ import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
18
18
  import { useNavbarState } from "../screen";
19
19
 
20
20
  export { useNavigation } from "./useNavigation";
@@ -127,11 +127,13 @@ export function isNavBarVisible(
127
127
 
128
128
  export const useBackHandler = (cb: () => boolean) => {
129
129
  useEffect(() => {
130
- BackHandler.addEventListener("hardwareBackPress", cb);
130
+ if (!isWeb()) {
131
+ const unsubscribe = BackHandler.addEventListener("hardwareBackPress", cb);
131
132
 
132
- return () => {
133
- BackHandler.removeEventListener("hardwareBackPress", cb);
134
- };
133
+ return () => {
134
+ unsubscribe.remove();
135
+ };
136
+ }
135
137
  }, [cb]);
136
138
  };
137
139
 
@@ -28,19 +28,14 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
28
28
 
29
29
  type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
30
30
 
31
- export const useRoute = (
32
- useLegacy = true
33
- ): {
31
+ export const useRoute = (): {
34
32
  screenData: VariousScreenData;
35
33
  pathname: string;
36
34
  } => {
37
35
  const pathname = usePathname() || "";
38
36
  const navigator = useNavigation();
39
- const screenContext = useContext(ScreenDataContext);
40
37
 
41
- const screenDataContext = useLegacy
42
- ? legacyScreenData(screenContext)
43
- : screenContext;
38
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
44
39
 
45
40
  const { plugins, contentTypes, rivers } = usePickFromState([
46
41
  "plugins",
@@ -14,6 +14,10 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
14
14
 
15
15
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
16
 
17
+ jest.mock(
18
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
19
+ );
20
+
17
21
  const { useCellResolver } = require("../useCellResolver");
18
22
 
19
23
  describe("cellResolver", () => {
@@ -1,5 +1,5 @@
1
1
  export { useRivers } from "./useRivers";
2
2
 
3
- export { useHomeRiver } from "./useHomeRiver";
3
+ export { useHomeRiver, getHomeRiver } from "./useHomeRiver";
4
4
 
5
5
  export { ZStoreProvider, useZStore } from "./ZStoreProvider";
@@ -1,8 +1,10 @@
1
- import * as R from "ramda";
2
1
  import { useRivers } from "./useRivers";
3
2
 
3
+ export const getHomeRiver = (rivers: Record<string, ZappRiver>) =>
4
+ Object.values(rivers).find((river: ZappRiver) => river.home);
5
+
4
6
  export const useHomeRiver = () => {
5
7
  const rivers = useRivers();
6
8
 
7
- return R.compose(R.find(R.propEq("home", true)), R.values)(rivers);
9
+ return getHomeRiver(rivers);
8
10
  };
@@ -1,9 +1,8 @@
1
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import {
2
+ useAppSelector,
3
+ selectRivers,
4
+ } from "@applicaster/zapp-react-native-redux";
2
5
 
3
- const riversSelector = ["rivers"];
4
-
5
- export const useRivers = () => {
6
- const { rivers } = usePickFromState(riversSelector as any);
7
-
8
- return rivers;
9
- };
6
+ export function useRivers(): Record<string, ZappRiver> {
7
+ return useAppSelector(selectRivers);
8
+ }
@@ -0,0 +1,7 @@
1
+ export const getFocusableId = (id) => `PickerItem.${id}`;
2
+
3
+ export const getPickerSelectorId = (id) => `PickerSelector.${id}`;
4
+
5
+ export const SCREEN_PICKER_CONTAINER = "ScreenPickerContainer";
6
+
7
+ export const getScreenPickerId = (id) => `${SCREEN_PICKER_CONTAINER}.${id}`;
@@ -1,17 +1,16 @@
1
- import * as R from "ramda";
2
-
1
+ import { SafeAreaProvider } from "react-native-safe-area-context";
2
+ import { render } from "@testing-library/react-native";
3
3
  import React, { PropsWithChildren } from "react";
4
- import { View } from "react-native";
5
-
4
+ import configureStore from "redux-mock-store";
6
5
  import { Provider } from "react-redux";
6
+ import { View } from "react-native";
7
7
  import thunk from "redux-thunk";
8
- import configureStore from "redux-mock-store";
9
- import { SafeAreaProvider } from "react-native-safe-area-context";
8
+ import * as R from "ramda";
9
+
10
10
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
11
11
 
12
- import { render } from "@testing-library/react-native";
13
- import { AnalyticsProvider } from "../analyticsUtils";
14
12
  import { ThemeContext } from "../theme";
13
+ import { AnalyticsProvider } from "../analyticsUtils";
15
14
 
16
15
  export { getByTestId } from "./getByTestId";
17
16
 
@@ -11,7 +11,7 @@ class BackgroundTimer {
11
11
  this.uniqueId = 0;
12
12
  this.callbacks = {};
13
13
 
14
- const EventEmitter = platformSelect({
14
+ const EventEmitter: typeof DeviceEventEmitter | undefined = platformSelect({
15
15
  android: DeviceEventEmitter,
16
16
  android_tv: DeviceEventEmitter,
17
17
  amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
@@ -0,0 +1,36 @@
1
+ import { find } from "../find";
2
+
3
+ test("example 1", () => {
4
+ const predicate = <T>(_: T, index: number): boolean => index === 0;
5
+ const xs = ["1", "2", "2", "3", "4"];
6
+
7
+ expect(find(predicate, xs)).toBe("1");
8
+ });
9
+
10
+ test("example 2", () => {
11
+ const predicate = <T>(_: T, index: number): boolean => index === 0;
12
+ const xs: string[] = [];
13
+
14
+ expect(find(predicate, xs)).toBe(undefined);
15
+ });
16
+
17
+ test("example 3", () => {
18
+ const predicate = () => false;
19
+ const xs = ["1", "2", "2", "3"];
20
+
21
+ expect(find(predicate, xs)).toBe(undefined);
22
+ });
23
+
24
+ test("example 4", () => {
25
+ const predicate = <T>(_: T, index: number): boolean => index === 1;
26
+ const xs = ["1", "2", "2", "3"];
27
+
28
+ expect(find(predicate, xs)).toBe("2");
29
+ });
30
+
31
+ test("example 5", () => {
32
+ const predicate = <T>(_: T, index: number): boolean => index === 2;
33
+ const xs = ["1", "2.1", "2", "3", "2", "4"];
34
+
35
+ expect(find(predicate, xs)).toBe("2");
36
+ });
@@ -0,0 +1,37 @@
1
+ import { pathOr } from "../pathOr";
2
+
3
+ test("example 1", () => {
4
+ const defaultValue = "defaultValue";
5
+ const path = ["a", "b", "c"];
6
+ const xs = { a: { b: { c: 1 } } };
7
+
8
+ const output = 1;
9
+
10
+ expect(pathOr(defaultValue, path, xs)).toEqual(output);
11
+ });
12
+
13
+ test("example 2", () => {
14
+ const defaultValue = "defaultValue";
15
+ const path = ["a", "b"];
16
+ const xs = { a: { b: { c: 1 } } };
17
+
18
+ const output = { c: 1 };
19
+
20
+ expect(pathOr(defaultValue, path, xs)).toEqual(output);
21
+ });
22
+
23
+ test("example 3", () => {
24
+ const defaultValue = "defaultValue";
25
+ const path = ["a", "b", "x"];
26
+ const xs = { a: { b: { c: 1 } } };
27
+
28
+ expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
29
+ });
30
+
31
+ test("example 4", () => {
32
+ const defaultValue = "defaultValue";
33
+ const path = ["a", "b", "c"];
34
+ const xs = undefined;
35
+
36
+ expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
37
+ });
@@ -0,0 +1,30 @@
1
+ import { startsWith } from "../startsWith";
2
+
3
+ describe("startsWith", () => {
4
+ it("returns false when str is null", () => {
5
+ expect(startsWith("a", null)).toBe(false);
6
+ });
7
+
8
+ it("returns false when str is undefined", () => {
9
+ expect(startsWith("a", undefined)).toBe(false);
10
+ });
11
+
12
+ it("returns true when string starts with target", () => {
13
+ expect(startsWith("he", "hello")).toBe(true);
14
+ expect(startsWith("", "hello")).toBe(true); // empty target always matches
15
+ });
16
+
17
+ it("returns false when string does not start with target", () => {
18
+ expect(startsWith("yo", "hello")).toBe(false);
19
+ });
20
+
21
+ it("works with single character target", () => {
22
+ expect(startsWith("h", "hello")).toBe(true);
23
+ expect(startsWith("x", "hello")).toBe(false);
24
+ });
25
+
26
+ it("is case-sensitive", () => {
27
+ expect(startsWith("He", "hello")).toBe(false);
28
+ expect(startsWith("he", "hello")).toBe(true);
29
+ });
30
+ });
package/utils/find.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const find = (predicate, xs) => {
2
+ return (xs || []).find((x, index) => predicate(x, index));
3
+ };