@applicaster/quick-brick-core 15.0.0-rc.12 → 15.0.0-rc.121

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 (26) hide show
  1. package/App/ActionSetters/index.ts +5 -4
  2. package/App/ActionsProvider/ActionsProvider.tsx +6 -1
  3. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +12 -27
  4. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +197 -104
  5. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +4 -7
  6. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler.ts +42 -30
  7. package/App/DeepLinking/URLSchemeHandler/URLSchemeHandler.tsx +4 -1
  8. package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +20 -13
  9. package/App/DeepLinking/URLSchemeListener/index.tsx +3 -4
  10. package/App/ErrorBoundary/__tests__/store.test.js +1 -1
  11. package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +6 -1
  12. package/App/NavigationProvider/Loader.tsx +3 -4
  13. package/App/NavigationProvider/NavigationProvider.tsx +29 -40
  14. package/App/NavigationProvider/ScreenHooks/usePluginScreenHooks.ts +2 -2
  15. package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +193 -152
  16. package/App/NavigationProvider/navigator/selectors.ts +21 -5
  17. package/App/NetworkStatusProvider/NetworkStatusProvider.tsx +2 -2
  18. package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +4 -4
  19. package/App/ThemeManager/index.tsx +9 -0
  20. package/App/ThemeManager/utils.ts +54 -0
  21. package/App/__tests__/createQuickBrickApp.test.js +1 -1
  22. package/App/appRemoteDataLoader/index.tsx +2 -2
  23. package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +1 -1
  24. package/App/remoteContextReloader/helpers.ts +3 -3
  25. package/package.json +8 -8
  26. package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap +0 -24
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
- import { cleanup, render, waitFor } from "@testing-library/react-native";
2
+ import { StyleSheet } from "react-native";
3
+ import { cleanup } from "@testing-library/react-native";
4
+ import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
3
5
 
4
6
  const theme = {
5
7
  screen_margin_top: 0,
@@ -10,14 +12,6 @@ jest.mock(
10
12
  "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
11
13
  );
12
14
 
13
- jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
14
- useTheme: jest.fn(() => theme),
15
- }));
16
-
17
- jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
18
- usePickFromState: jest.fn(() => ({})),
19
- }));
20
-
21
15
  const { URLSchemeHandler } = require("../URLSchemeHandler");
22
16
  const schemeHooks = require("../SchemeHandlerHooks/useUrlSchemeHandler");
23
17
 
@@ -36,12 +30,25 @@ describe("URLSchemeHandler", () => {
36
30
 
37
31
  afterEach(cleanup);
38
32
 
39
- it("renders correctly and invokes the hook", async () => {
40
- const wrapper = await waitFor(() =>
41
- render(<URLSchemeHandler url={url} onFinish={onFinish} />)
33
+ it("renders correctly and invokes the hook", () => {
34
+ const wrapper = renderWithProviders(
35
+ <URLSchemeHandler url={url} onFinish={onFinish} />,
36
+ {},
37
+ theme
42
38
  );
43
39
 
44
- expect(wrapper.toJSON()).toMatchSnapshot();
40
+ expect(wrapper.getByTestId("URLSchemeHandler")).toBeTruthy();
41
+
42
+ expect(
43
+ StyleSheet.flatten(wrapper.getByTestId("URLSchemeHandler").props.style)
44
+ ).toMatchObject({
45
+ alignItems: "center",
46
+ backgroundColor: "white",
47
+ flex: 1,
48
+ height: 1334,
49
+ justifyContent: "center",
50
+ width: 750,
51
+ });
45
52
 
46
53
  expect(hookSpy).toHaveBeenCalledWith(
47
54
  expect.objectContaining({ url, onFinish })
@@ -3,16 +3,15 @@ import React, { useCallback, useContext } from "react";
3
3
  import { URLSchemeHandler } from "../URLSchemeHandler";
4
4
  import { URLSchemeContext } from "./URLSchemeContextProvider";
5
5
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
6
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
6
+ import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
7
+ import { selectAppReady } from "@applicaster/zapp-react-native-redux";
7
8
 
8
9
  export function URLSchemeListener({ children }: { children: React.ReactNode }) {
9
10
  const { url, done } = useContext(URLSchemeContext);
10
11
 
11
12
  const navigator = useNavigation();
12
13
 
13
- const { appState } = usePickFromState(["appState"]);
14
-
15
- const appReady = appState?.appReady;
14
+ const appReady = useAppSelector(selectAppReady);
16
15
 
17
16
  const onFinish = useCallback(
18
17
  (callback) => {
@@ -1,4 +1,4 @@
1
- import { act, renderHook } from "@testing-library/react-hooks";
1
+ import { act, renderHook } from "@testing-library/react-native";
2
2
  import { useErrorStore } from "../store";
3
3
 
4
4
  describe("Error Store", () => {
@@ -42,12 +42,17 @@ const defaultBottomOffset = platformSelect({
42
42
  android: 0,
43
43
  });
44
44
 
45
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
46
+
45
47
  const getSheetHeight = ({ height, bottomOffset, maxHeight }) => {
46
48
  return platformSelect({
47
49
  ios: height - bottomOffset,
48
50
  default:
49
51
  (height || maxHeight) -
50
- (isAndroidPlatform() && !isAndroidVersionAtLeast(35) ? bottomOffset : 0),
52
+ (isAndroidPlatform() &&
53
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION)
54
+ ? bottomOffset
55
+ : 0),
51
56
  });
52
57
  };
53
58
 
@@ -2,8 +2,9 @@ import React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
3
 
4
4
  import { Spinner } from "@applicaster/zapp-react-native-ui-components/Components/Spinner";
5
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
+ import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
6
6
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
7
+ import { selectAppLaunched } from "@applicaster/zapp-react-native-redux";
7
8
 
8
9
  type Props = {
9
10
  children: React.ReactChild;
@@ -21,9 +22,7 @@ const styles = StyleSheet.create({
21
22
  });
22
23
 
23
24
  export function Loader({ children }: Props) {
24
- const {
25
- appState: { appLaunched },
26
- } = usePickFromState(["appState"]);
25
+ const appLaunched = useAppSelector(selectAppLaunched);
27
26
 
28
27
  const { currentRoute } = useNavigation();
29
28
 
@@ -7,16 +7,12 @@ import {
7
7
  getTargetRoute,
8
8
  usesVideoModal,
9
9
  } from "@applicaster/zapp-react-native-utils/navigationUtils";
10
- import { last } from "@applicaster/zapp-react-native-utils/utils";
10
+ import { clone, last } from "@applicaster/zapp-react-native-utils/utils";
11
11
  import {
12
12
  allowedOrientationsForScreen,
13
13
  useGetScreenOrientation,
14
14
  } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
15
15
  import { focusManager } from "@applicaster/zapp-react-native-utils/focusManager/FocusManager";
16
- import {
17
- useContentTypes,
18
- usePickFromState,
19
- } from "@applicaster/zapp-react-native-redux/hooks";
20
16
 
21
17
  import reducer, {
22
18
  ACTIONS,
@@ -44,6 +40,7 @@ import {
44
40
  activeRiverSelector,
45
41
  homeRiverSelector,
46
42
  lastEntrySelector,
43
+ startUpHookPluginIdentifiersSelector,
47
44
  } from "./navigator/selectors";
48
45
 
49
46
  import { coreAppLogger } from "../logger";
@@ -79,6 +76,16 @@ import { Hook } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager
79
76
  import { URLSchemeContext } from "../DeepLinking/URLSchemeListener/URLSchemeContextProvider";
80
77
 
81
78
  import { loadingOverlayManager } from "../LoadingOverlay";
79
+ import {
80
+ selectAppLaunched,
81
+ useAppSelector,
82
+ useContentTypes,
83
+ usePlugins,
84
+ } from "@applicaster/zapp-react-native-redux";
85
+ import {
86
+ useLayoutVersion,
87
+ useRivers,
88
+ } from "@applicaster/zapp-react-native-utils/reactHooks";
82
89
 
83
90
  const logger = coreAppLogger.addSubsystem("Navigator");
84
91
 
@@ -100,22 +107,11 @@ const platform = getPlatform();
100
107
  export function NavigationProvider({ children }: Props) {
101
108
  const { url: deepLinkURL } = React.useContext(URLSchemeContext);
102
109
 
103
- const {
104
- appData: { layoutVersion },
105
- rivers,
106
- plugins,
107
- pluginConfigurations,
108
- appState: { appLaunched },
109
- } = usePickFromState([
110
- "appData",
111
- "rivers",
112
- "plugins",
113
- "pluginConfigurations",
114
- "appState",
115
- "contentTypes",
116
- ]);
117
-
110
+ const appLaunched = useAppSelector(selectAppLaunched);
111
+ const layoutVersion = useLayoutVersion();
112
+ const rivers = useRivers();
118
113
  const contentTypes = useContentTypes();
114
+ const plugins = usePlugins();
119
115
 
120
116
  const [state, dispatch] = React.useReducer<
121
117
  NavigationReducer,
@@ -227,6 +223,7 @@ export function NavigationProvider({ children }: Props) {
227
223
  };
228
224
 
229
225
  const isVideoModalDocked = () =>
226
+ state?.options.videoModal.visible &&
230
227
  state?.options.videoModal.mode === "MINIMIZED";
231
228
 
232
229
  // TODO: Remove as it's using a concept of "current" route.
@@ -249,22 +246,24 @@ export function NavigationProvider({ children }: Props) {
249
246
  const screen = rivers[screenId];
250
247
  const parent = findParent(context, navigator.currentRoute);
251
248
 
249
+ const entryClone = clone(entry);
250
+
252
251
  if (!screen) {
253
252
  logger.warn({
254
253
  message: `Cannot resolve type mapping for ${screenId} id`,
255
- data: { entry, screenId },
254
+ data: { entry: entryClone, screenId },
256
255
  });
257
256
 
258
257
  return;
259
258
  }
260
259
 
261
260
  if (parent) {
262
- entry.parent = parent?.data;
261
+ entryClone.parent = parent?.data;
263
262
 
264
- entry.parentId = parent?.id;
263
+ entryClone.parentId = parent?.id;
265
264
  }
266
265
 
267
- dispatch(setNestedContent(pathname, entry, screen));
266
+ dispatch(setNestedContent(pathname, entryClone, screen));
268
267
  };
269
268
 
270
269
  const pushItem = (item, options = {}) => {
@@ -477,21 +476,11 @@ export function NavigationProvider({ children }: Props) {
477
476
  openLoadingOverlay();
478
477
  };
479
478
 
480
- const checkStartUpHooks = React.useMemo(() => {
481
- if (!pluginConfigurations) return false;
482
-
483
- const startUpHooksIdentifiers = R.compose(
484
- R.map((item) => item.plugin.identifier),
485
- R.filter(
486
- R.allPass([
487
- R.pathEq(["plugin", "api", "require_startup_execution"], true),
488
- R.pathEq(["plugin", "react_native"], true),
489
- R.pathEq(["plugin", "preload"], true),
490
- ])
491
- ),
492
- R.values
493
- )(pluginConfigurations);
479
+ const startUpHooksIdentifiers = useAppSelector(
480
+ startUpHookPluginIdentifiersSelector
481
+ );
494
482
 
483
+ const checkStartUpHooks = React.useMemo(() => {
495
484
  if (startUpHooksIdentifiers?.length) {
496
485
  const startUpHooks = R.filter(
497
486
  (plugin) => R.includes(plugin.identifier, startUpHooksIdentifiers),
@@ -523,7 +512,7 @@ export function NavigationProvider({ children }: Props) {
523
512
  }
524
513
 
525
514
  return false;
526
- }, [pluginConfigurations, plugins, rivers]);
515
+ }, [startUpHooksIdentifiers, plugins, rivers]);
527
516
 
528
517
  const [startUpHooks, _setStartUpHooks] = React.useState(checkStartUpHooks);
529
518
  const currentStartUpHooks = React.useRef(checkStartUpHooks);
@@ -726,7 +715,7 @@ export function NavigationProvider({ children }: Props) {
726
715
  activeRiver,
727
716
  getPathname: () => pathnameRef.current, // hack use to fix issue causing broken navigation as currentRoute is unreliable
728
717
  currentRoute: pathname, // TODO: remove. Current route shouldn't be needed
729
- previousAction: lastEntrySelector(state)
718
+ previousAction: (lastEntrySelector(state) as any)
730
719
  ?.action as QuickBrickNavigationActionType,
731
720
  push: pushItem,
732
721
  replace: replaceItem,
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import * as R from "ramda";
3
3
 
4
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
4
+ import { usePlugins } from "@applicaster/zapp-react-native-redux";
5
5
 
6
6
  enum ReactHooks {
7
7
  useEffect = "useEffect",
@@ -39,7 +39,7 @@ function invokeScreenHook(hooksWrappers) {
39
39
  }
40
40
 
41
41
  export function usePluginScreenHooks(pathname: string) {
42
- const { plugins } = usePickFromState(["plugins"]);
42
+ const plugins = usePlugins();
43
43
 
44
44
  const hooks = React.useMemo(
45
45
  () => R.filter(hasScreenHook, plugins) || [],