@applicaster/quick-brick-core 15.1.4 → 16.0.0-alpha.1042942411

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 (38) hide show
  1. package/App/ActionSetters/index.ts +5 -4
  2. package/App/ActionsProvider/ActionsProvider.tsx +31 -9
  3. package/App/ActionsProvider/LegacyActionsRegistryAdapter.tsx +107 -0
  4. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +12 -27
  5. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +197 -104
  6. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +4 -7
  7. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler.ts +42 -30
  8. package/App/DeepLinking/URLSchemeHandler/URLSchemeHandler.tsx +4 -1
  9. package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +20 -13
  10. package/App/DeepLinking/URLSchemeListener/index.tsx +3 -4
  11. package/App/ErrorBoundary/__tests__/store.test.js +1 -1
  12. package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/__tests__/index.test.tsx +88 -0
  13. package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +30 -56
  14. package/App/NavigationProvider/Loader.tsx +3 -4
  15. package/App/NavigationProvider/NavigationProvider.tsx +22 -35
  16. package/App/NavigationProvider/ScreenHooks/usePluginScreenHooks.ts +2 -2
  17. package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +193 -152
  18. package/App/NavigationProvider/navigator/selectors.ts +21 -5
  19. package/App/NetworkStatusProvider/NetworkStatusProvider.tsx +2 -2
  20. package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +4 -4
  21. package/App/NotificationToastRenderer/NotificationToastManager.ts +203 -0
  22. package/App/NotificationToastRenderer/NotificationToastRenderer.tsx +102 -0
  23. package/App/NotificationToastRenderer/NotificationToastRenderer.web.tsx +61 -0
  24. package/App/NotificationToastRenderer/__tests__/NotificationToastManager.test.ts +213 -0
  25. package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.test.tsx +85 -0
  26. package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.web.test.tsx +90 -0
  27. package/App/NotificationToastRenderer/__tests__/useNotificationHeight.test.tsx +53 -0
  28. package/App/NotificationToastRenderer/__tests__/useNotificationToastState.test.ts +112 -0
  29. package/App/NotificationToastRenderer/index.tsx +5 -0
  30. package/App/NotificationToastRenderer/useNotificationHeight.tsx +14 -0
  31. package/App/NotificationToastRenderer/useNotificationToastState.tsx +12 -0
  32. package/App/__tests__/createQuickBrickApp.test.js +1 -1
  33. package/App/appRemoteDataLoader/index.tsx +2 -2
  34. package/App/index.tsx +8 -5
  35. package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +1 -1
  36. package/App/remoteContextReloader/helpers.ts +3 -3
  37. package/package.json +8 -8
  38. package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap +0 -24
@@ -0,0 +1,90 @@
1
+ import React from "react";
2
+ import { Text } from "react-native";
3
+ import TestRenderer, { act } from "react-test-renderer";
4
+
5
+ import { notificationToastManager } from "../NotificationToastManager";
6
+ import { NotificationToastRenderer } from "../NotificationToastRenderer.web";
7
+
8
+ // This variant renders plain DOM tags (div/h2/h4) for web, which
9
+ // @testing-library/react-native's `render` cannot host-detect, so it is
10
+ // exercised directly with react-test-renderer instead.
11
+ describe("NotificationToastRenderer (web)", () => {
12
+ beforeAll(() => {
13
+ jest.spyOn(console, "log").mockImplementation(() => {});
14
+ });
15
+
16
+ afterAll(() => {
17
+ (console.log as jest.Mock).mockRestore();
18
+ });
19
+
20
+ afterEach(() => {
21
+ for (let i = 0; i < 10; i++) {
22
+ notificationToastManager.dismiss();
23
+ }
24
+
25
+ jest.restoreAllMocks();
26
+ jest.spyOn(console, "log").mockImplementation(() => {});
27
+ });
28
+
29
+ const createRenderer = (element: React.ReactElement) => {
30
+ let renderer;
31
+
32
+ act(() => {
33
+ renderer = TestRenderer.create(element);
34
+ });
35
+
36
+ return renderer;
37
+ };
38
+
39
+ it("renders its children", () => {
40
+ const renderer = createRenderer(
41
+ <NotificationToastRenderer>
42
+ <Text>child content</Text>
43
+ </NotificationToastRenderer>
44
+ );
45
+
46
+ expect(renderer.root.findByType(Text).props.children).toBe("child content");
47
+ });
48
+
49
+ it("renders nothing for the toast body until a toast is shown", () => {
50
+ const renderer = createRenderer(<NotificationToastRenderer />);
51
+
52
+ expect(
53
+ renderer.root.findAll(
54
+ (node) =>
55
+ node.props["data-testid"] === "NotificationToastRenderer-touchable"
56
+ )
57
+ ).toHaveLength(0);
58
+ });
59
+
60
+ it("shows the toast message once the manager emits one", () => {
61
+ const renderer = createRenderer(<NotificationToastRenderer />);
62
+
63
+ act(() => {
64
+ notificationToastManager.showToast({ message: "You are offline" });
65
+ });
66
+
67
+ const message = renderer.root.find(
68
+ (node) =>
69
+ node.props["data-testid"] === "NotificationToastRenderer-message"
70
+ );
71
+
72
+ expect(message.props.children).toBe("You are offline");
73
+ });
74
+
75
+ it("dismisses the toast when the root element is clicked", () => {
76
+ const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
77
+
78
+ const renderer = createRenderer(<NotificationToastRenderer />);
79
+
80
+ const root = renderer.root.find(
81
+ (node) => node.props["data-testid"] === "NotificationToastRenderer"
82
+ );
83
+
84
+ act(() => {
85
+ root.props.onClick();
86
+ });
87
+
88
+ expect(dismissSpy).toHaveBeenCalled();
89
+ });
90
+ });
@@ -0,0 +1,53 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+
3
+ let mockInsets = { top: 0 };
4
+
5
+ jest.mock("react-native-safe-area-context", () => ({
6
+ useSafeAreaInsets: () => mockInsets,
7
+ }));
8
+
9
+ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
10
+ ...jest.requireActual("@applicaster/zapp-react-native-utils/reactUtils"),
11
+ platformSelect: jest.fn(({ ios, android }) => ({ ios, android })),
12
+ }));
13
+
14
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
15
+ import { useNotificationHeight } from "../useNotificationHeight";
16
+
17
+ describe("useNotificationHeight", () => {
18
+ beforeEach(() => {
19
+ (platformSelect as jest.Mock).mockClear();
20
+ });
21
+
22
+ it("adds the safe area top inset to the platform nav bar height", () => {
23
+ mockInsets = { top: 44 };
24
+ (platformSelect as jest.Mock).mockReturnValueOnce(56);
25
+
26
+ const { result } = renderHook(() => useNotificationHeight());
27
+
28
+ expect(result.current).toEqual({
29
+ statusHeight: 44,
30
+ notificationHeight: 100,
31
+ });
32
+ });
33
+
34
+ it("falls back to a 0 status height when there is no top inset", () => {
35
+ mockInsets = { top: 0 };
36
+ (platformSelect as jest.Mock).mockReturnValueOnce(44);
37
+
38
+ const { result } = renderHook(() => useNotificationHeight());
39
+
40
+ expect(result.current).toEqual({
41
+ statusHeight: 0,
42
+ notificationHeight: 44,
43
+ });
44
+ });
45
+
46
+ it("selects the nav bar height per platform via platformSelect", () => {
47
+ mockInsets = { top: 20 };
48
+
49
+ renderHook(() => useNotificationHeight());
50
+
51
+ expect(platformSelect).toHaveBeenCalledWith({ ios: 44, android: 56 });
52
+ });
53
+ });
@@ -0,0 +1,112 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+
3
+ import { notificationToastManager } from "../NotificationToastManager";
4
+ import { useNotificationToastState } from "../useNotificationToastState";
5
+
6
+ jest.useFakeTimers();
7
+
8
+ describe("useNotificationToastState", () => {
9
+ beforeAll(() => {
10
+ jest.spyOn(console, "log").mockImplementation(() => {});
11
+ });
12
+
13
+ afterAll(() => {
14
+ (console.log as jest.Mock).mockRestore();
15
+ });
16
+
17
+ afterEach(() => {
18
+ // drain whatever is left showing/queued so the next test starts clean;
19
+ // the hook's own effect cleanup (on unmount) removes its SHOW/HIDE
20
+ // handlers automatically via RNTL's auto-cleanup.
21
+ for (let i = 0; i < 10; i++) {
22
+ notificationToastManager.dismiss();
23
+ }
24
+
25
+ jest.restoreAllMocks();
26
+ jest.spyOn(console, "log").mockImplementation(() => {});
27
+ });
28
+
29
+ it("starts with no toast", () => {
30
+ const { result } = renderHook(() => useNotificationToastState());
31
+
32
+ expect(result.current).toBeNull();
33
+ });
34
+
35
+ it("reflects the toast emitted by the manager's SHOW event", () => {
36
+ const { result } = renderHook(() => useNotificationToastState());
37
+
38
+ act(() => {
39
+ notificationToastManager.showToast({ message: "hello" });
40
+ });
41
+
42
+ expect(result.current).toEqual(
43
+ expect.objectContaining({ message: "hello" })
44
+ );
45
+ });
46
+
47
+ it("clears the toast when the manager emits HIDE", () => {
48
+ const { result } = renderHook(() => useNotificationToastState());
49
+
50
+ act(() => {
51
+ notificationToastManager.showToast({ message: "hello" });
52
+ });
53
+
54
+ expect(result.current).not.toBeNull();
55
+
56
+ act(() => {
57
+ notificationToastManager.dismiss();
58
+ });
59
+
60
+ expect(result.current).toBeNull();
61
+ });
62
+
63
+ it("stops updating after unmount", () => {
64
+ const { result, unmount } = renderHook(() => useNotificationToastState());
65
+
66
+ unmount();
67
+
68
+ act(() => {
69
+ notificationToastManager.showToast({ message: "after unmount" });
70
+ });
71
+
72
+ expect(result.current).toBeNull();
73
+ });
74
+
75
+ it("subscribes on mount and disposes the subscription on unmount", () => {
76
+ const dispose = jest.fn();
77
+
78
+ const subscribeSpy = jest
79
+ .spyOn(notificationToastManager, "subscribe")
80
+ .mockReturnValue(dispose);
81
+
82
+ const { unmount } = renderHook(() => useNotificationToastState());
83
+
84
+ expect(subscribeSpy).toHaveBeenCalledWith(expect.any(Function));
85
+ expect(dispose).not.toHaveBeenCalled();
86
+
87
+ unmount();
88
+
89
+ expect(dispose).toHaveBeenCalledTimes(1);
90
+ });
91
+
92
+ it("subscribe registers SHOW/HIDE handlers and its disposer removes them", () => {
93
+ const callback = jest.fn();
94
+
95
+ const dispose = notificationToastManager.subscribe(callback);
96
+
97
+ act(() => {
98
+ notificationToastManager.showToast({ message: "hello" }); // emits SHOW
99
+ });
100
+
101
+ expect(callback).toHaveBeenCalled();
102
+
103
+ callback.mockClear();
104
+ dispose();
105
+
106
+ act(() => {
107
+ notificationToastManager.showToast({ message: "again" }); // emits SHOW
108
+ });
109
+
110
+ expect(callback).not.toHaveBeenCalled();
111
+ });
112
+ });
@@ -0,0 +1,5 @@
1
+ export { notificationToastManager } from "./NotificationToastManager";
2
+
3
+ export { NotificationToastRenderer } from "./NotificationToastRenderer";
4
+
5
+ export { useNotificationHeight } from "./useNotificationHeight";
@@ -0,0 +1,14 @@
1
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
2
+
3
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+
5
+ export const useNotificationHeight = () => {
6
+ const insets = useSafeAreaInsets();
7
+
8
+ const navBarHeight = platformSelect({ ios: 44, android: 56 });
9
+
10
+ const statusHeight = insets.top;
11
+ const notificationHeight = statusHeight + navBarHeight;
12
+
13
+ return { statusHeight, notificationHeight };
14
+ };
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+
3
+ import { notificationToastManager } from "./NotificationToastManager";
4
+
5
+ export const useNotificationToastState = () => {
6
+ const state = React.useSyncExternalStore(
7
+ notificationToastManager.subscribe,
8
+ notificationToastManager.getCurrentState
9
+ );
10
+
11
+ return state;
12
+ };
@@ -2,7 +2,7 @@
2
2
  import * as React from "react";
3
3
  import { render } from "@testing-library/react-native";
4
4
  import { Provider } from "react-redux";
5
- import thunk from "redux-thunk";
5
+ import { thunk } from "redux-thunk";
6
6
  import configureStore from "redux-mock-store";
7
7
 
8
8
  jest.mock(
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  import { getRemoteContextData } from "../remoteContextReloader/getRemoteContextData";
4
4
 
5
5
  import { coreAppLogger } from "../logger";
6
- import { AnyAction, Dispatch } from "@reduxjs/toolkit";
6
+ import { UnknownAction, Dispatch } from "@reduxjs/toolkit";
7
7
  import { isAndroidPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
8
8
 
9
9
  const logger = coreAppLogger.addSubsystem("AppRemoteDataLoader");
@@ -27,7 +27,7 @@ export function appRemoteDataLoader(Component: ReactComponent<any>) {
27
27
  const [isDataLoaded, setIsDataLoaded] = React.useState(false);
28
28
 
29
29
  const loadRemoteConfigurationJSONs = async (
30
- dispatch: Dispatch<AnyAction>,
30
+ dispatch: Dispatch<UnknownAction>,
31
31
  state
32
32
  ) => {
33
33
  if (!__DEV__ || process.env.ENABLE_REMOTE_DATA_IN_DEV === "true") {
package/App/index.tsx CHANGED
@@ -31,6 +31,7 @@ import { withActionExecutor } from "@applicaster/zapp-react-native-utils/actions
31
31
  import { withScreenDataContextProvider } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
32
32
  import { LogicAggregatorContainer } from "./LogicAggregatorContainer";
33
33
  import { LoadingOverlay } from "./LoadingOverlay";
34
+ import { NotificationToastRenderer } from "./NotificationToastRenderer";
34
35
  import { ZappAppWrapper } from "./components/ZappAppWrapper";
35
36
 
36
37
  interface AppOptions {
@@ -67,11 +68,13 @@ const App = ({
67
68
  <ErrorBoundary>
68
69
  <URLSchemeListener>
69
70
  <SplashLoader>
70
- <OfflineHandler>
71
- <Layout>
72
- <RouteManager />
73
- </Layout>
74
- </OfflineHandler>
71
+ <NotificationToastRenderer>
72
+ <OfflineHandler>
73
+ <Layout>
74
+ <RouteManager />
75
+ </Layout>
76
+ </OfflineHandler>
77
+ </NotificationToastRenderer>
75
78
  </SplashLoader>
76
79
  <ModalProvider />
77
80
  </URLSchemeListener>
@@ -74,7 +74,7 @@ export async function getNativeRemoteContextData(
74
74
  );
75
75
  }
76
76
 
77
- const apiVersion = layout?.layout?.["api_version"]; // Taken from remote configuration
77
+ const apiVersion = layout?.layout?.api_version; // Taken from remote configuration
78
78
 
79
79
  dispatch(AppData.actions.merge({ layoutVersion: apiVersion || "v1" }));
80
80
 
@@ -113,15 +113,15 @@ export async function prepareRuntimeConfigurationUrls(
113
113
  }
114
114
  }
115
115
 
116
- export async function getPromiseForType(
116
+ export async function getPromiseForType<T = FileResponse>(
117
117
  key: string
118
- ): Promise<FileResponse | never> {
118
+ ): Promise<T | never> {
119
119
  try {
120
120
  const response = await AppLoaderBridge?.getFile(key, null);
121
121
 
122
122
  return {
123
123
  [key]: JSON.parse(response),
124
- };
124
+ } as T;
125
125
  } catch (e) {
126
126
  throw new Error("cannot retrieve configuration data for " + key);
127
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "15.1.4",
3
+ "version": "16.0.0-alpha.1042942411",
4
4
  "description": "Core package for Applicaster's Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "15.1.4",
32
- "@applicaster/quick-brick-core-plugins": "15.1.4",
33
- "@applicaster/zapp-pipes-v2-client": "15.1.4",
34
- "@applicaster/zapp-react-native-bridge": "15.1.4",
35
- "@applicaster/zapp-react-native-redux": "15.1.4",
36
- "@applicaster/zapp-react-native-ui-components": "15.1.4",
37
- "@applicaster/zapp-react-native-utils": "15.1.4",
31
+ "@applicaster/applicaster-types": "16.0.0-alpha.1042942411",
32
+ "@applicaster/quick-brick-core-plugins": "16.0.0-alpha.1042942411",
33
+ "@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.1042942411",
34
+ "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.1042942411",
35
+ "@applicaster/zapp-react-native-redux": "16.0.0-alpha.1042942411",
36
+ "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.1042942411",
37
+ "@applicaster/zapp-react-native-utils": "16.0.0-alpha.1042942411",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",
@@ -1,24 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`URLSchemeHandler renders correctly and invokes the hook 1`] = `
4
- <View
5
- style={
6
- [
7
- {
8
- "alignItems": "center",
9
- "flex": 1,
10
- "justifyContent": "center",
11
- },
12
- {
13
- "backgroundColor": "white",
14
- "height": 1334,
15
- "width": 750,
16
- },
17
- ]
18
- }
19
- >
20
- <ActivityIndicator
21
- size="large"
22
- />
23
- </View>
24
- `;