@applicaster/quick-brick-core 16.0.0-alpha.2480030155 → 16.0.0-alpha.2554311249

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.
@@ -60,11 +60,21 @@ jest.spyOn(useNavigationHooks, "useNavigation").mockReturnValue(navigator);
60
60
  const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
61
61
  const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
62
62
 
63
- const setEntryContext = jest.fn();
64
-
65
- jest.doMock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
63
+ const mockSetEntryContext = jest.fn();
64
+
65
+ // `jest.mock` is hoisted above the imports, so the entry context is replaced
66
+ // before anything can pull the real one in. `jest.doMock` is not hoisted, and
67
+ // only worked here for as long as no import above happened to load this module
68
+ // first - which any new import anywhere in the graph could silently undo,
69
+ // leaving the hook writing to the real context while the spy stayed at zero
70
+ // calls. The rest of the module is kept, since other consumers loaded by this
71
+ // graph read other exports from it.
72
+ jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
73
+ ...jest.requireActual(
74
+ "@applicaster/zapp-react-native-ui-components/Contexts"
75
+ ),
66
76
  ZappPipesEntryContext: {
67
- useZappPipesContext: () => [{}, setEntryContext],
77
+ useZappPipesContext: () => [{}, mockSetEntryContext],
68
78
  },
69
79
  }));
70
80
 
@@ -76,7 +86,7 @@ jest.mock("../../../logger", () => ({
76
86
  log_debug: jest.fn(),
77
87
  }));
78
88
 
79
- // to use import instead of require it's required to use jest.mock above
89
+ // Required after the mocks above, so the hook binds to them.
80
90
  const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
81
91
 
82
92
  const mockStoreObj = { rivers, contentTypes, pipesEndpoints, appData };
@@ -101,7 +111,7 @@ function clearMocks() {
101
111
  navigator.replace.mockClear();
102
112
  navigator.push.mockClear();
103
113
  navigator.goHome.mockClear();
104
- setEntryContext.mockClear();
114
+ mockSetEntryContext.mockClear();
105
115
  }
106
116
 
107
117
  describe("useOpenSchemeHandler", () => {
@@ -215,7 +225,7 @@ describe("useOpenSchemeHandler", () => {
215
225
  })
216
226
  );
217
227
 
218
- expect(setEntryContext).toHaveBeenCalledWith(
228
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
219
229
  expect.objectContaining({
220
230
  ...params,
221
231
  extensions: { ...params, initial_player_state: "fullscreen" },
@@ -272,7 +282,7 @@ describe("useOpenSchemeHandler", () => {
272
282
  })
273
283
  );
274
284
 
275
- expect(setEntryContext).toHaveBeenCalledWith(
285
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
276
286
  expect.objectContaining({
277
287
  ...params,
278
288
  extensions: { ...params, initial_player_state: "fullscreen" },
@@ -331,7 +341,7 @@ describe("useOpenSchemeHandler", () => {
331
341
  })
332
342
  );
333
343
 
334
- expect(setEntryContext).toHaveBeenCalledWith(
344
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
335
345
  entryWithInitialPlayerState
336
346
  );
337
347
  };
@@ -361,7 +371,7 @@ describe("useOpenSchemeHandler", () => {
361
371
  })
362
372
  );
363
373
 
364
- expect(setEntryContext).toHaveBeenCalledWith(
374
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
365
375
  entryWithInitialPlayerState
366
376
  );
367
377
  };
@@ -391,7 +401,7 @@ describe("useOpenSchemeHandler", () => {
391
401
  })
392
402
  );
393
403
 
394
- expect(setEntryContext).toHaveBeenCalledWith(
404
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
395
405
  entryWithInitialPlayerState
396
406
  );
397
407
  };
@@ -421,7 +431,7 @@ describe("useOpenSchemeHandler", () => {
421
431
  })
422
432
  );
423
433
 
424
- expect(setEntryContext).toHaveBeenCalledWith(
434
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
425
435
  entryWithInitialPlayerState
426
436
  );
427
437
  };
@@ -451,7 +461,7 @@ describe("useOpenSchemeHandler", () => {
451
461
  })
452
462
  );
453
463
 
454
- expect(setEntryContext).toHaveBeenCalledWith(
464
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
455
465
  entryWithInitialPlayerState
456
466
  );
457
467
  };
@@ -485,7 +495,7 @@ describe("useOpenSchemeHandler", () => {
485
495
  })
486
496
  );
487
497
 
488
- expect(setEntryContext).toHaveBeenCalledWith(
498
+ expect(mockSetEntryContext).toHaveBeenCalledWith(
489
499
  expect.objectContaining(entryWithInitialPlayerState)
490
500
  );
491
501
  };
@@ -514,7 +524,7 @@ describe("useOpenSchemeHandler", () => {
514
524
  );
515
525
 
516
526
  expect(navigator.goHome).toHaveBeenCalled();
517
- expect(setEntryContext).not.toHaveBeenCalled();
527
+ expect(mockSetEntryContext).not.toHaveBeenCalled();
518
528
  };
519
529
 
520
530
  await testHook({
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { LayoutChangeEvent, Platform, StyleSheet, View } from "react-native";
2
+ import { LayoutChangeEvent, StyleSheet, View } from "react-native";
3
3
 
4
4
  import { Handle, HandleProps } from "./Handle";
5
5
  import { DraggableBottomSheet } from "./DraggableBottomSheet";
@@ -11,9 +11,12 @@ import {
11
11
  import {
12
12
  isAndroidPlatform,
13
13
  isAndroidVersionAtLeast,
14
+ isApplePlatform,
14
15
  platformSelect,
15
16
  } from "@applicaster/zapp-react-native-utils/reactUtils";
16
17
 
18
+ import { useKeyboardHeight } from "./hooks";
19
+
17
20
  type Props = {
18
21
  children: React.ReactChild;
19
22
  backgroundColor: string;
@@ -104,6 +107,8 @@ export function ModalBottomSheetFrame(props: Props) {
104
107
 
105
108
  const sheetHeight = useGetSheetHeight(height, maxHeight);
106
109
 
110
+ const keyboardHeight = useKeyboardHeight();
111
+
107
112
  return (
108
113
  <DraggableBottomSheet
109
114
  sheetHeight={sheetHeight}
@@ -113,7 +118,9 @@ export function ModalBottomSheetFrame(props: Props) {
113
118
  header={(dragging) => <Handle {...handleProps} focused={dragging} />}
114
119
  maxWidth={maxWidth}
115
120
  {...dimensions}
116
- height={safeAreaDims.height - (Platform.OS === "ios" ? bottom : 0)}
121
+ height={
122
+ safeAreaDims.height - (isApplePlatform() ? bottom : 0) - keyboardHeight
123
+ }
117
124
  >
118
125
  <SafeAreaView
119
126
  edges={["left", "right", "bottom"]}
@@ -0,0 +1,105 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+ import { Keyboard } from "react-native";
3
+
4
+ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
5
+ isApplePlatform: () => false,
6
+ }));
7
+
8
+ // Import after mocks so module-level isApple resolves to false.
9
+ // eslint-disable-next-line import/first
10
+ import { useKeyboardHeight } from "../useKeyboardHeight";
11
+
12
+ type KeyboardListener = (event?: {
13
+ endCoordinates: { height: number };
14
+ }) => void;
15
+
16
+ function setupKeyboardListenerMock() {
17
+ const listeners: Record<string, KeyboardListener> = {};
18
+ const removeMocks: Record<string, jest.Mock> = {};
19
+
20
+ const addListenerSpy = jest
21
+ .spyOn(Keyboard, "addListener")
22
+ .mockImplementation((event: string, callback: KeyboardListener) => {
23
+ listeners[event] = callback;
24
+
25
+ const remove = jest.fn();
26
+ removeMocks[event] = remove;
27
+
28
+ return { remove };
29
+ });
30
+
31
+ return { listeners, removeMocks, addListenerSpy };
32
+ }
33
+
34
+ describe("useKeyboardHeight (non-Apple platforms)", () => {
35
+ let listeners: Record<string, KeyboardListener>;
36
+ let removeMocks: Record<string, jest.Mock>;
37
+ let addListenerSpy: jest.SpyInstance;
38
+
39
+ beforeEach(() => {
40
+ const mock = setupKeyboardListenerMock();
41
+ listeners = mock.listeners;
42
+ removeMocks = mock.removeMocks;
43
+ addListenerSpy = mock.addListenerSpy;
44
+ });
45
+
46
+ afterEach(() => {
47
+ addListenerSpy.mockRestore();
48
+ });
49
+
50
+ it("returns 0 initially and subscribes to didShow / didHide events", () => {
51
+ const { result } = renderHook(() => useKeyboardHeight());
52
+
53
+ expect(result.current).toBe(0);
54
+ expect(addListenerSpy).toHaveBeenCalledTimes(2);
55
+
56
+ expect(addListenerSpy).toHaveBeenCalledWith(
57
+ "keyboardDidShow",
58
+ expect.any(Function)
59
+ );
60
+
61
+ expect(addListenerSpy).toHaveBeenCalledWith(
62
+ "keyboardDidHide",
63
+ expect.any(Function)
64
+ );
65
+ });
66
+
67
+ it("updates height when keyboardDidShow fires", () => {
68
+ const { result } = renderHook(() => useKeyboardHeight());
69
+
70
+ act(() => {
71
+ listeners.keyboardDidShow?.({
72
+ endCoordinates: { height: 412 },
73
+ });
74
+ });
75
+
76
+ expect(result.current).toBe(412);
77
+ });
78
+
79
+ it("resets height to 0 when keyboardDidHide fires", () => {
80
+ const { result } = renderHook(() => useKeyboardHeight());
81
+
82
+ act(() => {
83
+ listeners.keyboardDidShow?.({
84
+ endCoordinates: { height: 412 },
85
+ });
86
+ });
87
+
88
+ expect(result.current).toBe(412);
89
+
90
+ act(() => {
91
+ listeners.keyboardDidHide?.();
92
+ });
93
+
94
+ expect(result.current).toBe(0);
95
+ });
96
+
97
+ it("removes listeners on unmount", () => {
98
+ const { unmount } = renderHook(() => useKeyboardHeight());
99
+
100
+ unmount();
101
+
102
+ expect(removeMocks.keyboardDidShow).toHaveBeenCalledTimes(1);
103
+ expect(removeMocks.keyboardDidHide).toHaveBeenCalledTimes(1);
104
+ });
105
+ });
@@ -0,0 +1,102 @@
1
+ import { act, renderHook } from "@testing-library/react-native";
2
+ import { Keyboard } from "react-native";
3
+ import { useKeyboardHeight } from "../useKeyboardHeight";
4
+
5
+ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
6
+ isApplePlatform: () => true,
7
+ }));
8
+
9
+ type KeyboardListener = (event?: {
10
+ endCoordinates: { height: number };
11
+ }) => void;
12
+
13
+ function setupKeyboardListenerMock() {
14
+ const listeners: Record<string, KeyboardListener> = {};
15
+ const removeMocks: Record<string, jest.Mock> = {};
16
+
17
+ const addListenerSpy = jest
18
+ .spyOn(Keyboard, "addListener")
19
+ .mockImplementation((event: string, callback: KeyboardListener) => {
20
+ listeners[event] = callback;
21
+
22
+ const remove = jest.fn();
23
+ removeMocks[event] = remove;
24
+
25
+ return { remove };
26
+ });
27
+
28
+ return { listeners, removeMocks, addListenerSpy };
29
+ }
30
+
31
+ describe("useKeyboardHeight (Apple platforms)", () => {
32
+ let listeners: Record<string, KeyboardListener>;
33
+ let removeMocks: Record<string, jest.Mock>;
34
+ let addListenerSpy: jest.SpyInstance;
35
+
36
+ beforeEach(() => {
37
+ const mock = setupKeyboardListenerMock();
38
+ listeners = mock.listeners;
39
+ removeMocks = mock.removeMocks;
40
+ addListenerSpy = mock.addListenerSpy;
41
+ });
42
+
43
+ afterEach(() => {
44
+ addListenerSpy.mockRestore();
45
+ });
46
+
47
+ it("returns 0 initially and subscribes to willShow / willHide events", () => {
48
+ const { result } = renderHook(() => useKeyboardHeight());
49
+
50
+ expect(result.current).toBe(0);
51
+ expect(addListenerSpy).toHaveBeenCalledTimes(2);
52
+
53
+ expect(addListenerSpy).toHaveBeenCalledWith(
54
+ "keyboardWillShow",
55
+ expect.any(Function)
56
+ );
57
+
58
+ expect(addListenerSpy).toHaveBeenCalledWith(
59
+ "keyboardWillHide",
60
+ expect.any(Function)
61
+ );
62
+ });
63
+
64
+ it("updates height when keyboardWillShow fires", () => {
65
+ const { result } = renderHook(() => useKeyboardHeight());
66
+
67
+ act(() => {
68
+ listeners.keyboardWillShow?.({
69
+ endCoordinates: { height: 336 },
70
+ });
71
+ });
72
+
73
+ expect(result.current).toBe(336);
74
+ });
75
+
76
+ it("resets height to 0 when keyboardWillHide fires", () => {
77
+ const { result } = renderHook(() => useKeyboardHeight());
78
+
79
+ act(() => {
80
+ listeners.keyboardWillShow?.({
81
+ endCoordinates: { height: 280 },
82
+ });
83
+ });
84
+
85
+ expect(result.current).toBe(280);
86
+
87
+ act(() => {
88
+ listeners.keyboardWillHide?.();
89
+ });
90
+
91
+ expect(result.current).toBe(0);
92
+ });
93
+
94
+ it("removes listeners on unmount", () => {
95
+ const { unmount } = renderHook(() => useKeyboardHeight());
96
+
97
+ unmount();
98
+
99
+ expect(removeMocks.keyboardWillShow).toHaveBeenCalledTimes(1);
100
+ expect(removeMocks.keyboardWillHide).toHaveBeenCalledTimes(1);
101
+ });
102
+ });
@@ -0,0 +1 @@
1
+ export { useKeyboardHeight } from "./useKeyboardHeight";
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { Keyboard, KeyboardEvent } from "react-native";
3
+ import { isApplePlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+
5
+ const isApple = isApplePlatform();
6
+
7
+ export function useKeyboardHeight() {
8
+ const [keyboardHeight, setKeyboardHeight] = React.useState(0);
9
+
10
+ React.useEffect(() => {
11
+ // iOS supports smooth 'willShow' / 'willHide' events
12
+ const showEvent = isApple ? "keyboardWillShow" : "keyboardDidShow";
13
+ const hideEvent = isApple ? "keyboardWillHide" : "keyboardDidHide";
14
+
15
+ const showListener = Keyboard.addListener(showEvent, (e: KeyboardEvent) => {
16
+ setKeyboardHeight(e.endCoordinates.height);
17
+ });
18
+
19
+ const hideListener = Keyboard.addListener(hideEvent, () => {
20
+ setKeyboardHeight(0);
21
+ });
22
+
23
+ return () => {
24
+ showListener.remove();
25
+ hideListener.remove();
26
+ };
27
+ }, []);
28
+
29
+ return keyboardHeight;
30
+ }
@@ -47,9 +47,11 @@ export function ModalBottomSheet(props: Props) {
47
47
 
48
48
  const {
49
49
  ModalBottomSheetContent = ModalComponent,
50
- modalBottomSheetContentProps,
50
+ modalBottomSheetContentProps = {},
51
51
  } = props;
52
52
 
53
+ const { key, ...restContentProps } = modalBottomSheetContentProps;
54
+
53
55
  useEffect(() => {
54
56
  Keyboard.dismiss();
55
57
  }, []);
@@ -82,11 +84,12 @@ export function ModalBottomSheet(props: Props) {
82
84
  }}
83
85
  >
84
86
  <ModalBottomSheetContent
87
+ key={key as any}
85
88
  width={
86
89
  Math.min(sheetTabletMaxWidth, dimensions.width) || dimensions.width
87
90
  }
88
91
  maxHeight={sheetMaxHeight}
89
- {...modalBottomSheetContentProps}
92
+ {...restContentProps}
90
93
  dismiss={dismiss}
91
94
  currentRoute={navigator.currentRoute}
92
95
  />
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
 
3
3
  import { View, StyleSheet } from "react-native";
4
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
4
5
 
5
6
  import { ScreenResolver } from "@applicaster/zapp-react-native-ui-components/Components/ScreenResolver";
6
7
 
@@ -17,6 +18,8 @@ const styles = StyleSheet.create({
17
18
  export function ModalContent(props: Props) {
18
19
  const { modalScreenProps } = props;
19
20
 
21
+ const insets = useSafeAreaInsets();
22
+
20
23
  if (modalScreenProps?.screenData?.modalBottomSheetContentProps) {
21
24
  const { ModalBottomSheetContent, modalBottomSheetContentProps } =
22
25
  modalScreenProps?.screenData || {};
@@ -30,7 +33,20 @@ export function ModalContent(props: Props) {
30
33
  }
31
34
 
32
35
  return (
33
- <View style={styles.container}>
36
+ // A presented screen fills the window, including the status bar and home
37
+ // indicator. Inset it so chrome it draws at its own edges — a close button,
38
+ // for example — stays inside the tappable area.
39
+ <View
40
+ style={[
41
+ styles.container,
42
+ {
43
+ paddingTop: insets.top,
44
+ paddingBottom: insets.bottom,
45
+ paddingLeft: insets.left,
46
+ paddingRight: insets.right,
47
+ },
48
+ ]}
49
+ >
34
50
  <ScreenResolver {...modalScreenProps} />
35
51
  </View>
36
52
  );
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ import { StyleSheet } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ import { ModalContent } from "../ModalContent";
6
+
7
+ jest.mock("../ModalBottomSheet", () => ({ ModalBottomSheet: () => null }));
8
+
9
+ jest.mock("react-native-safe-area-context", () => ({
10
+ useSafeAreaInsets: () => ({ top: 59, bottom: 34, left: 0, right: 0 }),
11
+ }));
12
+
13
+ jest.mock(
14
+ "@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
15
+ () => ({ ScreenResolver: () => null })
16
+ );
17
+
18
+ const flatStyle = (tree: any) => StyleSheet.flatten(tree.props.style);
19
+
20
+ describe("ModalContent", () => {
21
+ it("insets a presented screen by the safe area so its chrome stays tappable", () => {
22
+ const tree = render(
23
+ <ModalContent modalScreenProps={{ screenId: "river-1" }} />
24
+ ).toJSON();
25
+
26
+ expect(flatStyle(tree)).toMatchObject({
27
+ paddingTop: 59,
28
+ paddingBottom: 34,
29
+ });
30
+ });
31
+
32
+ it("leaves a bottom sheet full-bleed", () => {
33
+ const tree = render(
34
+ <ModalContent
35
+ modalScreenProps={{
36
+ screenData: { modalBottomSheetContentProps: { items: [] } },
37
+ }}
38
+ />
39
+ ).toJSON();
40
+
41
+ // Bottom sheets anchor to the screen edge and manage their own insets.
42
+ expect(tree).toBeNull();
43
+ });
44
+ });
@@ -0,0 +1,75 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+
4
+ import { modalStore } from "@applicaster/zapp-react-native-utils/modalState";
5
+
6
+ import { ModalProvider } from "../";
7
+
8
+ /**
9
+ * Records the ScreenDataContext value seen by the presented screen — the
10
+ * context useScreenContext()/useCurrentScreenData() read from.
11
+ */
12
+ const mockSeenScreenData: any[] = [];
13
+
14
+ jest.mock(
15
+ "@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
16
+ () => {
17
+ const ReactLocal = require("react");
18
+
19
+ const {
20
+ ScreenDataContext,
21
+ } = require("@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext");
22
+
23
+ return {
24
+ ScreenResolver: () => {
25
+ mockSeenScreenData.push(ReactLocal.useContext(ScreenDataContext));
26
+
27
+ return null;
28
+ },
29
+ };
30
+ }
31
+ );
32
+
33
+ // Needs the navigator + redux to build navbar state; irrelevant to this test.
34
+ jest.mock(
35
+ "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext",
36
+ () => ({
37
+ ScreenContextProvider: ({ children }: any) => children,
38
+ })
39
+ );
40
+
41
+ // Pulls in the whole Components barrel; only the ScreenResolver branch matters here.
42
+ jest.mock("../ModalBottomSheet", () => ({ ModalBottomSheet: () => null }));
43
+
44
+ jest.mock("react-native-safe-area-context", () => ({
45
+ useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
46
+ }));
47
+
48
+ const river = { id: "river-parent-lock", type: "parent_lock" } as any;
49
+
50
+ const entry = { id: "entry-1", type: { value: "video" } } as any;
51
+
52
+ const seen = () => mockSeenScreenData[mockSeenScreenData.length - 1];
53
+
54
+ describe("ModalProvider", () => {
55
+ beforeEach(() => {
56
+ mockSeenScreenData.length = 0;
57
+ modalStore.getState().dismissModal();
58
+ });
59
+
60
+ it("gives the presented screen its screen and entry through ScreenDataContext", () => {
61
+ modalStore.getState().openModal({ item: river, props: { entry } });
62
+
63
+ render(<ModalProvider />);
64
+
65
+ expect(seen()).toEqual({ screen: river, entry });
66
+ });
67
+
68
+ it("gives the presented screen its screen when presented without an entry", () => {
69
+ modalStore.getState().openModal({ item: river });
70
+
71
+ render(<ModalProvider />);
72
+
73
+ expect(seen()).toMatchObject({ screen: river });
74
+ });
75
+ });
@@ -4,6 +4,7 @@ import { ModalPresenter } from "./ModalPresenter";
4
4
  import { ModalContent } from "./ModalContent";
5
5
  import { ModalChildrenWrapper } from "./ModalChildrenWrapper";
6
6
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
7
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
7
8
  import { ScreenContextProvider } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
8
9
  import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
9
10
  import { useModalStoreState } from "@applicaster/zapp-react-native-utils/modalState";
@@ -14,6 +15,9 @@ export function ModalProvider() {
14
15
  const [modalVisible, setModalVisible] = React.useState(false);
15
16
  const [modalShown, setModalShown] = React.useState(false);
16
17
 
18
+ const screen = modalState?.screen;
19
+ const entry = modalState?.props?.entry as ZappEntry | undefined;
20
+
17
21
  React.useEffect(() => {
18
22
  setModalVisible(!!modalState);
19
23
 
@@ -22,13 +26,25 @@ export function ModalProvider() {
22
26
  }
23
27
  }, [modalState]);
24
28
 
25
- if (!modalState?.screen) {
29
+ /**
30
+ * The modal renders as a sibling of the stack navigator, so nothing upstream
31
+ * provides ScreenDataContext and the presented screen would otherwise see
32
+ * `null` from useScreenContext()/useCurrentScreenData(). Provide it here so a
33
+ * presented screen resolves its own screen and entry, the same way a pushed
34
+ * screen does through the navigator's scene.
35
+ */
36
+ const screenDataContextValue = React.useMemo(
37
+ () => ({ screen, entry }),
38
+ [screen, entry]
39
+ );
40
+
41
+ if (!screen) {
26
42
  return null;
27
43
  }
28
44
 
29
45
  const modalScreenProps = {
30
- screenData: modalState?.screen,
31
- screenId: modalState?.screen?.id,
46
+ screenData: entry ? { ...entry, targetScreen: screen } : screen,
47
+ screenId: screen?.id,
32
48
  screenType: "river",
33
49
  ...modalState.props,
34
50
  };
@@ -39,17 +55,19 @@ export function ModalProvider() {
39
55
 
40
56
  return (
41
57
  <PathnameContext.Provider value={pathname}>
42
- <ScreenContextProvider pathname={pathname}>
43
- <ModalPresenter
44
- visible={shouldShowModal}
45
- {...modalState?.options}
46
- statusBarTranslucent
47
- >
48
- <ModalChildrenWrapper>
49
- <ModalContent modalScreenProps={modalScreenProps} />
50
- </ModalChildrenWrapper>
51
- </ModalPresenter>
52
- </ScreenContextProvider>
58
+ <ScreenDataContext.Provider value={screenDataContextValue}>
59
+ <ScreenContextProvider pathname={pathname}>
60
+ <ModalPresenter
61
+ visible={shouldShowModal}
62
+ {...modalState?.options}
63
+ statusBarTranslucent
64
+ >
65
+ <ModalChildrenWrapper>
66
+ <ModalContent modalScreenProps={modalScreenProps} />
67
+ </ModalChildrenWrapper>
68
+ </ModalPresenter>
69
+ </ScreenContextProvider>
70
+ </ScreenDataContext.Provider>
53
71
  </PathnameContext.Provider>
54
72
  );
55
73
  }
@@ -55,6 +55,7 @@ import {
55
55
  getTargetScreen,
56
56
  legacyScreenData,
57
57
  openExternalUrl,
58
+ stripHookPrefix,
58
59
  } from "./utils";
59
60
  import {
60
61
  debounce,
@@ -414,6 +415,19 @@ export function NavigationProvider({ children }: Props) {
414
415
  },
415
416
  dispose
416
417
  ) => {
418
+ logger.debug({
419
+ message: `Hook screen presented: ${
420
+ hookPlugin.isModalHook() ? `(modal) ${route}` : route
421
+ }`,
422
+ data: {
423
+ route,
424
+ hookIdentifier: hookPlugin?.identifier,
425
+ hookScreenId: hookPlugin?.screen_id,
426
+ isModal: hookPlugin.isModalHook(),
427
+ lastHook: hookPlugin?.lastHook,
428
+ },
429
+ });
430
+
417
431
  if (hookPlugin?.lastHook) {
418
432
  dispose();
419
433
  }
@@ -536,6 +550,17 @@ export function NavigationProvider({ children }: Props) {
536
550
  currentStartUpHooks.current && setStartUpHooks(false);
537
551
  }
538
552
 
553
+ logger.debug({
554
+ message: `Hooks complete, navigating to: ${targetRoute}`,
555
+ data: {
556
+ targetRoute,
557
+ hookIdentifier: hookPlugin?.identifier,
558
+ screenId: screen?.id,
559
+ screenName: screen?.name,
560
+ options,
561
+ },
562
+ });
563
+
539
564
  dispatch(
540
565
  navigationAction(targetRoute, { screen, entry: payload, options })
541
566
  );
@@ -574,12 +599,28 @@ export function NavigationProvider({ children }: Props) {
574
599
  ) => {
575
600
  const { entry, screen, targetRoute, externalUrl } = getNavigationTarget(
576
601
  item,
577
- action === ACTIONS.REPLACE ? "" : pathnameRef.current,
602
+ action === ACTIONS.REPLACE ? "" : stripHookPrefix(pathnameRef.current),
578
603
  contentTypes,
579
604
  layoutVersion,
580
605
  rivers
581
606
  );
582
607
 
608
+ logger.debug({
609
+ message: `Navigating: ${pathnameRef.current || "(none)"} -> ${
610
+ targetRoute || externalUrl || "(unresolved)"
611
+ }`,
612
+ data: {
613
+ action,
614
+ from: pathnameRef.current,
615
+ to: targetRoute,
616
+ externalUrl,
617
+ screenId: screen?.id,
618
+ screenName: screen?.name,
619
+ entryType: entry?.type?.value,
620
+ options,
621
+ },
622
+ });
623
+
583
624
  if (externalUrl) {
584
625
  const openURL = async (url) => {
585
626
  const inflatedURL = await inflateUrl(url);
@@ -668,6 +709,15 @@ export function NavigationProvider({ children }: Props) {
668
709
 
669
710
  hooksManager.handleHooks(legacyScreenData({ entry, screen }));
670
711
  } else {
712
+ logger.debug({
713
+ message: `Navigating offline (hooks skipped) to: ${targetRoute}`,
714
+ data: {
715
+ targetRoute,
716
+ screenId: screen?.id,
717
+ screenName: screen?.name,
718
+ },
719
+ });
720
+
671
721
  dispatch(navigationAction(targetRoute, { screen, entry, options }));
672
722
  }
673
723
  },
@@ -1,4 +1,4 @@
1
- const { targetShouldOpenExternally } = require("../utils");
1
+ const { targetShouldOpenExternally, stripHookPrefix } = require("../utils");
2
2
 
3
3
  const mockedOpenUrl = jest.fn();
4
4
 
@@ -116,3 +116,33 @@ describe("targetShouldOpenExternally", () => {
116
116
  });
117
117
  });
118
118
  });
119
+
120
+ describe("stripHookPrefix", () => {
121
+ const HOOK = "203d96a9-f4af-49d1-9890-435e683b9274";
122
+ const MANAGE = "9f8e1e06-abd6-48b9-b73a-4caf4601f870";
123
+
124
+ it("drops the hook segment so a hook screen navigates from the root", () => {
125
+ expect(stripHookPrefix(`/hooks/${HOOK}`)).toBe("");
126
+ });
127
+
128
+ it("keeps the screens opened from a hook, without their hook prefix", () => {
129
+ expect(stripHookPrefix(`/hooks/${HOOK}/river/${MANAGE}`)).toBe(
130
+ `/river/${MANAGE}`
131
+ );
132
+ });
133
+
134
+ it("leaves a regular route untouched", () => {
135
+ expect(stripHookPrefix(`/river/${MANAGE}`)).toBe(`/river/${MANAGE}`);
136
+ });
137
+
138
+ it("only strips a hook segment at the start of the path", () => {
139
+ expect(stripHookPrefix(`/river/${MANAGE}/hooks/${HOOK}`)).toBe(
140
+ `/river/${MANAGE}/hooks/${HOOK}`
141
+ );
142
+ });
143
+
144
+ it("returns an empty prefix for an empty or missing path", () => {
145
+ expect(stripHookPrefix("")).toBe("");
146
+ expect(stripHookPrefix(undefined)).toBe("");
147
+ });
148
+ });
@@ -18,6 +18,20 @@ const WEBVIEW_SCREEN_IDENTIFIER = "webview_screen_qb";
18
18
 
19
19
  const logger = coreAppLogger.addSubsystem("Navigator");
20
20
 
21
+ /**
22
+ * Drops a leading `/hooks/<screen_id>` segment from a path.
23
+ *
24
+ * Routes are built by appending to the current path, and a hook screen is
25
+ * presented at an absolute `/hooks/<screen_id>`. Without this, every screen
26
+ * opened from a hook would inherit that prefix for good: the hook's stack entry
27
+ * would stay buried under its descendants, and `canGoBack` — which treats any
28
+ * route containing `/hooks` as a hook — would count the whole branch as one
29
+ * entry and send Back home instead of popping.
30
+ */
31
+ export function stripHookPrefix(pathname?: string): string {
32
+ return pathname?.replace(/^\/hooks\/[^/]+/, "") ?? "";
33
+ }
34
+
21
35
  export function targetShouldOpenExternally(
22
36
  target: ZappEntry,
23
37
  targetScreen: ZappRiver | null,
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * NotificationToastRenderer for TV platforms.
5
+ * Currently, it does not render anything except for the children passed to it.
6
+ */
7
+
8
+ export const NotificationToastRenderer = ({ children }) => {
9
+ return <>{children}</>;
10
+ };
@@ -6,6 +6,4 @@ export { CONFIRMATION_TOAST_SOURCE } from "./NotificationToastManager";
6
6
 
7
7
  export { NotificationToastRenderer } from "./NotificationToastRenderer";
8
8
 
9
- export { useNotificationHeight } from "./useNotificationHeight";
10
-
11
9
  export { resolveConfirmationToastStyle } from "./resolveConfirmationToastStyle";
@@ -1,6 +1,7 @@
1
1
  import { useSafeAreaInsets } from "react-native-safe-area-context";
2
2
  import { getNavbarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
3
3
 
4
+ /** Hook calculates the height of the notification area including the status bar and navigation bar, used only for mobile */
4
5
  export const useNotificationHeight = () => {
5
6
  const insets = useSafeAreaInsets();
6
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "16.0.0-alpha.2480030155",
3
+ "version": "16.0.0-alpha.2554311249",
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": "16.0.0-alpha.2480030155",
32
- "@applicaster/quick-brick-core-plugins": "16.0.0-alpha.2480030155",
33
- "@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.2480030155",
34
- "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.2480030155",
35
- "@applicaster/zapp-react-native-redux": "16.0.0-alpha.2480030155",
36
- "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.2480030155",
37
- "@applicaster/zapp-react-native-utils": "16.0.0-alpha.2480030155",
31
+ "@applicaster/applicaster-types": "16.0.0-alpha.2554311249",
32
+ "@applicaster/quick-brick-core-plugins": "16.0.0-alpha.2554311249",
33
+ "@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.2554311249",
34
+ "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.2554311249",
35
+ "@applicaster/zapp-react-native-redux": "16.0.0-alpha.2554311249",
36
+ "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.2554311249",
37
+ "@applicaster/zapp-react-native-utils": "16.0.0-alpha.2554311249",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",