@applicaster/quick-brick-core 16.0.0-alpha.1535029240 → 16.0.0-alpha.1701179921
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.
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +25 -15
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/__tests__/index.test.tsx +88 -0
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +30 -56
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +9 -2
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.android.test.ts +105 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.test.ts +102 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/index.ts +1 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/useKeyboardHeight.ts +30 -0
- package/App/ModalProvider/ModalBottomSheet/index.tsx +5 -2
- package/App/ModalProvider/ModalContent.tsx +3 -0
- package/App/ModalProvider/__tests__/ModalContent.test.tsx +39 -0
- package/App/ModalProvider/__tests__/index.test.tsx +99 -0
- package/App/ModalProvider/index.tsx +39 -14
- package/App/NavigationProvider/NavigationProvider.tsx +57 -5
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +56 -0
- package/App/NavigationProvider/__tests__/utils.test.ts +31 -1
- package/App/NavigationProvider/utils.ts +14 -0
- package/App/NotificationToastRenderer/NotificationToastManager.ts +13 -2
- package/App/NotificationToastRenderer/NotificationToastRenderer.tsx +56 -24
- package/App/NotificationToastRenderer/NotificationToastRenderer.tv.tsx +10 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastManager.test.ts +24 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.test.tsx +151 -3
- package/App/NotificationToastRenderer/__tests__/resolveConfirmationToastStyle.test.ts +118 -0
- package/App/NotificationToastRenderer/__tests__/useNotificationHeight.test.tsx +16 -11
- package/App/NotificationToastRenderer/index.tsx +5 -1
- package/App/NotificationToastRenderer/resolveConfirmationToastStyle.ts +33 -0
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +3 -3
- package/package.json +8 -8
|
@@ -30,6 +30,9 @@ export function ModalContent(props: Props) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
+
// A presented screen fills the window, including the status bar and home
|
|
34
|
+
// indicator. The modal wraps it in its own SafeAreaProvider, so the screen
|
|
35
|
+
// reads the real insets itself and places its own chrome inside them.
|
|
33
36
|
<View style={styles.container}>
|
|
34
37
|
<ScreenResolver {...modalScreenProps} />
|
|
35
38
|
</View>
|
|
@@ -0,0 +1,39 @@
|
|
|
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(
|
|
10
|
+
"@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
|
|
11
|
+
() => ({ ScreenResolver: () => null })
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const flatStyle = (tree: any) => StyleSheet.flatten(tree.props.style);
|
|
15
|
+
|
|
16
|
+
describe("ModalContent", () => {
|
|
17
|
+
it("lets a presented screen fill the modal, leaving the safe area to the screen", () => {
|
|
18
|
+
const tree = render(
|
|
19
|
+
<ModalContent modalScreenProps={{ screenId: "river-1" }} />
|
|
20
|
+
).toJSON();
|
|
21
|
+
|
|
22
|
+
// The modal provides a SafeAreaProvider instead, so the presented screen
|
|
23
|
+
// reads the real insets itself rather than being padded from the outside.
|
|
24
|
+
expect(flatStyle(tree)).toEqual({ flex: 1 });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("leaves a bottom sheet full-bleed", () => {
|
|
28
|
+
const tree = render(
|
|
29
|
+
<ModalContent
|
|
30
|
+
modalScreenProps={{
|
|
31
|
+
screenData: { modalBottomSheetContentProps: { items: [] } },
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
).toJSON();
|
|
35
|
+
|
|
36
|
+
// Bottom sheets anchor to the screen edge and manage their own insets.
|
|
37
|
+
expect(tree).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
/** Records the `initialMetrics` each SafeAreaProvider the modal renders got. */
|
|
15
|
+
const mockSafeAreaProviderMetrics: any[] = [];
|
|
16
|
+
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
|
|
19
|
+
() => {
|
|
20
|
+
const ReactLocal = require("react");
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
ScreenDataContext,
|
|
24
|
+
} = require("@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext");
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
ScreenResolver: () => {
|
|
28
|
+
mockSeenScreenData.push(ReactLocal.useContext(ScreenDataContext));
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Needs the navigator + redux to build navbar state; irrelevant to this test.
|
|
37
|
+
jest.mock(
|
|
38
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext",
|
|
39
|
+
() => ({
|
|
40
|
+
ScreenContextProvider: ({ children }: any) => children,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Pulls in the whole Components barrel; only the ScreenResolver branch matters here.
|
|
45
|
+
jest.mock("../ModalBottomSheet", () => ({ ModalBottomSheet: () => null }));
|
|
46
|
+
|
|
47
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
48
|
+
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
|
49
|
+
// A modal renders in its own native window, so it needs its own provider
|
|
50
|
+
// seeded with the window metrics; without them insets read as zero inside.
|
|
51
|
+
initialWindowMetrics: { insets: { top: 59, bottom: 34, left: 0, right: 0 } },
|
|
52
|
+
SafeAreaProvider: ({ children, initialMetrics }: any) => {
|
|
53
|
+
mockSafeAreaProviderMetrics.push(initialMetrics);
|
|
54
|
+
|
|
55
|
+
return children;
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
const river = { id: "river-parent-lock", type: "parent_lock" } as any;
|
|
60
|
+
|
|
61
|
+
const entry = { id: "entry-1", type: { value: "video" } } as any;
|
|
62
|
+
|
|
63
|
+
const seen = () => mockSeenScreenData[mockSeenScreenData.length - 1];
|
|
64
|
+
|
|
65
|
+
describe("ModalProvider", () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
mockSeenScreenData.length = 0;
|
|
68
|
+
mockSafeAreaProviderMetrics.length = 0;
|
|
69
|
+
modalStore.getState().dismissModal();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("gives the presented screen its screen and entry through ScreenDataContext", () => {
|
|
73
|
+
modalStore.getState().openModal({ item: river, props: { entry } });
|
|
74
|
+
|
|
75
|
+
render(<ModalProvider />);
|
|
76
|
+
|
|
77
|
+
expect(seen()).toEqual({ screen: river, entry });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("gives the presented screen its screen when presented without an entry", () => {
|
|
81
|
+
modalStore.getState().openModal({ item: river });
|
|
82
|
+
|
|
83
|
+
render(<ModalProvider />);
|
|
84
|
+
|
|
85
|
+
expect(seen()).toMatchObject({ screen: river });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("seeds the presented screen's safe area with the window metrics", () => {
|
|
89
|
+
const { initialWindowMetrics } = require("react-native-safe-area-context");
|
|
90
|
+
|
|
91
|
+
modalStore.getState().openModal({ item: river });
|
|
92
|
+
|
|
93
|
+
render(<ModalProvider />);
|
|
94
|
+
|
|
95
|
+
expect(mockSafeAreaProviderMetrics).toEqual(
|
|
96
|
+
expect.arrayContaining([initialWindowMetrics])
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
initialWindowMetrics,
|
|
5
|
+
SafeAreaProvider,
|
|
6
|
+
} from "react-native-safe-area-context";
|
|
7
|
+
|
|
3
8
|
import { ModalPresenter } from "./ModalPresenter";
|
|
4
9
|
import { ModalContent } from "./ModalContent";
|
|
5
10
|
import { ModalChildrenWrapper } from "./ModalChildrenWrapper";
|
|
6
11
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
12
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
7
13
|
import { ScreenContextProvider } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
|
|
8
14
|
import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
|
|
9
15
|
import { useModalStoreState } from "@applicaster/zapp-react-native-utils/modalState";
|
|
@@ -14,6 +20,9 @@ export function ModalProvider() {
|
|
|
14
20
|
const [modalVisible, setModalVisible] = React.useState(false);
|
|
15
21
|
const [modalShown, setModalShown] = React.useState(false);
|
|
16
22
|
|
|
23
|
+
const screen = modalState?.screen;
|
|
24
|
+
const entry = modalState?.props?.entry as ZappEntry | undefined;
|
|
25
|
+
|
|
17
26
|
React.useEffect(() => {
|
|
18
27
|
setModalVisible(!!modalState);
|
|
19
28
|
|
|
@@ -22,13 +31,25 @@ export function ModalProvider() {
|
|
|
22
31
|
}
|
|
23
32
|
}, [modalState]);
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The modal renders as a sibling of the stack navigator, so nothing upstream
|
|
36
|
+
* provides ScreenDataContext and the presented screen would otherwise see
|
|
37
|
+
* `null` from useScreenContext()/useCurrentScreenData(). Provide it here so a
|
|
38
|
+
* presented screen resolves its own screen and entry, the same way a pushed
|
|
39
|
+
* screen does through the navigator's scene.
|
|
40
|
+
*/
|
|
41
|
+
const screenDataContextValue = React.useMemo(
|
|
42
|
+
() => ({ screen, entry }),
|
|
43
|
+
[screen, entry]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!screen) {
|
|
26
47
|
return null;
|
|
27
48
|
}
|
|
28
49
|
|
|
29
50
|
const modalScreenProps = {
|
|
30
|
-
screenData:
|
|
31
|
-
screenId:
|
|
51
|
+
screenData: entry ? { ...entry, targetScreen: screen } : screen,
|
|
52
|
+
screenId: screen?.id,
|
|
32
53
|
screenType: "river",
|
|
33
54
|
...modalState.props,
|
|
34
55
|
};
|
|
@@ -39,17 +60,21 @@ export function ModalProvider() {
|
|
|
39
60
|
|
|
40
61
|
return (
|
|
41
62
|
<PathnameContext.Provider value={pathname}>
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
<ScreenDataContext.Provider value={screenDataContextValue}>
|
|
64
|
+
<ScreenContextProvider pathname={pathname}>
|
|
65
|
+
<ModalPresenter
|
|
66
|
+
visible={shouldShowModal}
|
|
67
|
+
{...modalState?.options}
|
|
68
|
+
statusBarTranslucent
|
|
69
|
+
>
|
|
70
|
+
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
|
|
71
|
+
<ModalChildrenWrapper>
|
|
72
|
+
<ModalContent modalScreenProps={modalScreenProps} />
|
|
73
|
+
</ModalChildrenWrapper>
|
|
74
|
+
</SafeAreaProvider>
|
|
75
|
+
</ModalPresenter>
|
|
76
|
+
</ScreenContextProvider>
|
|
77
|
+
</ScreenDataContext.Provider>
|
|
53
78
|
</PathnameContext.Provider>
|
|
54
79
|
);
|
|
55
80
|
}
|
|
@@ -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,
|
|
@@ -242,6 +243,10 @@ export function NavigationProvider({ children }: Props) {
|
|
|
242
243
|
playNextOverlayState.current = state;
|
|
243
244
|
};
|
|
244
245
|
|
|
246
|
+
// The play-next overlay owns remote focus while it is visible, so key
|
|
247
|
+
// handling (InteractionManager) needs to be able to ask for it.
|
|
248
|
+
const getPlayNextOverlay = () => playNextOverlayState.current ?? null;
|
|
249
|
+
|
|
245
250
|
const setNestedScreenContent = (entry: ZappEntry, screenId: string) => {
|
|
246
251
|
const screen = rivers[screenId];
|
|
247
252
|
const parent = findParent(context, navigator.currentRoute);
|
|
@@ -348,10 +353,7 @@ export function NavigationProvider({ children }: Props) {
|
|
|
348
353
|
state: firstRoute.state,
|
|
349
354
|
};
|
|
350
355
|
|
|
351
|
-
if (
|
|
352
|
-
stateForBack?.state?.entry &&
|
|
353
|
-
"home" in stateForBack?.state?.entry
|
|
354
|
-
) {
|
|
356
|
+
if (stateForBack?.state?.entry?.home) {
|
|
355
357
|
goHome();
|
|
356
358
|
} else {
|
|
357
359
|
dispatch(back(stateForBack));
|
|
@@ -414,6 +416,19 @@ export function NavigationProvider({ children }: Props) {
|
|
|
414
416
|
},
|
|
415
417
|
dispose
|
|
416
418
|
) => {
|
|
419
|
+
logger.debug({
|
|
420
|
+
message: `Hook screen presented: ${
|
|
421
|
+
hookPlugin.isModalHook() ? `(modal) ${route}` : route
|
|
422
|
+
}`,
|
|
423
|
+
data: {
|
|
424
|
+
route,
|
|
425
|
+
hookIdentifier: hookPlugin?.identifier,
|
|
426
|
+
hookScreenId: hookPlugin?.screen_id,
|
|
427
|
+
isModal: hookPlugin.isModalHook(),
|
|
428
|
+
lastHook: hookPlugin?.lastHook,
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
|
|
417
432
|
if (hookPlugin?.lastHook) {
|
|
418
433
|
dispose();
|
|
419
434
|
}
|
|
@@ -536,6 +551,17 @@ export function NavigationProvider({ children }: Props) {
|
|
|
536
551
|
currentStartUpHooks.current && setStartUpHooks(false);
|
|
537
552
|
}
|
|
538
553
|
|
|
554
|
+
logger.debug({
|
|
555
|
+
message: `Hooks complete, navigating to: ${targetRoute}`,
|
|
556
|
+
data: {
|
|
557
|
+
targetRoute,
|
|
558
|
+
hookIdentifier: hookPlugin?.identifier,
|
|
559
|
+
screenId: screen?.id,
|
|
560
|
+
screenName: screen?.name,
|
|
561
|
+
options,
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
|
|
539
565
|
dispatch(
|
|
540
566
|
navigationAction(targetRoute, { screen, entry: payload, options })
|
|
541
567
|
);
|
|
@@ -574,12 +600,28 @@ export function NavigationProvider({ children }: Props) {
|
|
|
574
600
|
) => {
|
|
575
601
|
const { entry, screen, targetRoute, externalUrl } = getNavigationTarget(
|
|
576
602
|
item,
|
|
577
|
-
action === ACTIONS.REPLACE ? "" : pathnameRef.current,
|
|
603
|
+
action === ACTIONS.REPLACE ? "" : stripHookPrefix(pathnameRef.current),
|
|
578
604
|
contentTypes,
|
|
579
605
|
layoutVersion,
|
|
580
606
|
rivers
|
|
581
607
|
);
|
|
582
608
|
|
|
609
|
+
logger.debug({
|
|
610
|
+
message: `Navigating: ${pathnameRef.current || "(none)"} -> ${
|
|
611
|
+
targetRoute || externalUrl || "(unresolved)"
|
|
612
|
+
}`,
|
|
613
|
+
data: {
|
|
614
|
+
action,
|
|
615
|
+
from: pathnameRef.current,
|
|
616
|
+
to: targetRoute,
|
|
617
|
+
externalUrl,
|
|
618
|
+
screenId: screen?.id,
|
|
619
|
+
screenName: screen?.name,
|
|
620
|
+
entryType: entry?.type?.value,
|
|
621
|
+
options,
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
|
|
583
625
|
if (externalUrl) {
|
|
584
626
|
const openURL = async (url) => {
|
|
585
627
|
const inflatedURL = await inflateUrl(url);
|
|
@@ -668,6 +710,15 @@ export function NavigationProvider({ children }: Props) {
|
|
|
668
710
|
|
|
669
711
|
hooksManager.handleHooks(legacyScreenData({ entry, screen }));
|
|
670
712
|
} else {
|
|
713
|
+
logger.debug({
|
|
714
|
+
message: `Navigating offline (hooks skipped) to: ${targetRoute}`,
|
|
715
|
+
data: {
|
|
716
|
+
targetRoute,
|
|
717
|
+
screenId: screen?.id,
|
|
718
|
+
screenName: screen?.name,
|
|
719
|
+
},
|
|
720
|
+
});
|
|
721
|
+
|
|
671
722
|
dispatch(navigationAction(targetRoute, { screen, entry, options }));
|
|
672
723
|
}
|
|
673
724
|
},
|
|
@@ -727,6 +778,7 @@ export function NavigationProvider({ children }: Props) {
|
|
|
727
778
|
replace: replaceItem,
|
|
728
779
|
setNestedScreenContent,
|
|
729
780
|
setPlayNextOverlay,
|
|
781
|
+
getPlayNextOverlay,
|
|
730
782
|
goHome,
|
|
731
783
|
canGoBack,
|
|
732
784
|
goBack,
|
|
@@ -410,6 +410,62 @@ describe("<NavigationProvider />", () => {
|
|
|
410
410
|
});
|
|
411
411
|
});
|
|
412
412
|
|
|
413
|
+
describe("when backToTop is requested from a non-home tab", () => {
|
|
414
|
+
const listenRiver = {
|
|
415
|
+
id: "LISTEN",
|
|
416
|
+
home: false,
|
|
417
|
+
navigations: [],
|
|
418
|
+
ui_components: [],
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
beforeEach(() => {
|
|
422
|
+
wrapper = renderContextConsumer({
|
|
423
|
+
...store,
|
|
424
|
+
rivers: { ...rivers, LISTEN: listenRiver },
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
act(() => {
|
|
428
|
+
getNavigatorValues(wrapper).navigator.replace(listenRiver);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("returns to the tab root from the second level", () => {
|
|
433
|
+
act(() => {
|
|
434
|
+
getNavigatorValues(wrapper).navigator.push(rivers.A1234);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
act(() => {
|
|
438
|
+
getNavigatorValues(wrapper).navigator.goBack(false, false, true);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
442
|
+
|
|
443
|
+
expect(navigator.currentRoute).toEqual("/river/LISTEN");
|
|
444
|
+
expect(navigator.activeRiver).toEqual(listenRiver);
|
|
445
|
+
expect(state.stack.mainStack).toHaveLength(1);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it("returns to the tab root from the third level", () => {
|
|
449
|
+
act(() => {
|
|
450
|
+
getNavigatorValues(wrapper).navigator.push(rivers.A1234);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
act(() => {
|
|
454
|
+
getNavigatorValues(wrapper).navigator.push(rivers.C0987);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
act(() => {
|
|
458
|
+
getNavigatorValues(wrapper).navigator.goBack(false, false, true);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
462
|
+
|
|
463
|
+
expect(navigator.currentRoute).toEqual("/river/LISTEN");
|
|
464
|
+
expect(navigator.activeRiver).toEqual(listenRiver);
|
|
465
|
+
expect(state.stack.mainStack).toHaveLength(1);
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
|
|
413
469
|
describe("when there is a previous route and there are hooks", () => {
|
|
414
470
|
beforeEach(() => {
|
|
415
471
|
wrapper = renderContextConsumer();
|
|
@@ -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,
|
|
@@ -24,12 +24,19 @@ export interface ToastStyle {
|
|
|
24
24
|
letterSpacing?: number;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export const DEFAULT_TOAST_TIMEOUT = 4000;
|
|
28
|
+
|
|
29
|
+
export const CONFIRMATION_TOAST_SOURCE = "confirmation";
|
|
30
|
+
|
|
27
31
|
export interface ToastPayload {
|
|
28
32
|
id?: string;
|
|
29
33
|
message: string;
|
|
30
34
|
extraMessage?: string; // secondary line; TV renderers show it as a subtitle, mobile ignores it
|
|
31
|
-
timeout?: number; // ms;
|
|
35
|
+
timeout?: number; // ms; defaults to DEFAULT_TOAST_TIMEOUT (4000) if omitted
|
|
32
36
|
style?: ToastStyle;
|
|
37
|
+
// stamped by the showToast action; Theme confirmation styles apply when
|
|
38
|
+
// source === CONFIRMATION_TOAST_SOURCE ("confirmation")
|
|
39
|
+
source?: string;
|
|
33
40
|
[key: string]: unknown;
|
|
34
41
|
}
|
|
35
42
|
|
|
@@ -122,7 +129,11 @@ class NotificationToastManager {
|
|
|
122
129
|
};
|
|
123
130
|
|
|
124
131
|
private handleShowToast = (payload: ToastPayload) => {
|
|
125
|
-
const item = {
|
|
132
|
+
const item = {
|
|
133
|
+
...payload,
|
|
134
|
+
id: payload.id ?? String(this.nextId++),
|
|
135
|
+
timeout: payload.timeout ?? DEFAULT_TOAST_TIMEOUT,
|
|
136
|
+
};
|
|
126
137
|
|
|
127
138
|
const queuedIndex = this.queue.findIndex((queued) => queued.id === item.id);
|
|
128
139
|
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
1
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { View, Text, Animated, StyleSheet, ViewStyle } from "react-native";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
Directions,
|
|
5
|
+
Gesture,
|
|
6
|
+
GestureDetector,
|
|
7
|
+
} from "react-native-gesture-handler";
|
|
8
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
CONFIRMATION_TOAST_SOURCE,
|
|
12
|
+
notificationToastManager,
|
|
13
|
+
} from "./NotificationToastManager";
|
|
12
14
|
import { useNotificationToastState } from "./useNotificationToastState";
|
|
13
15
|
import { useNotificationHeight } from "./useNotificationHeight";
|
|
16
|
+
import { resolveConfirmationToastStyle } from "./resolveConfirmationToastStyle";
|
|
17
|
+
|
|
18
|
+
const DEFAULT_TOAST_BACKGROUND_COLOR = "#000";
|
|
19
|
+
const DEFAULT_TOAST_MESSAGE_COLOR = "#fff";
|
|
14
20
|
|
|
15
21
|
const styles = StyleSheet.create({
|
|
16
22
|
notificationView: {
|
|
@@ -28,6 +34,7 @@ type NumberBoolean = 0 | 1;
|
|
|
28
34
|
|
|
29
35
|
export const NotificationToastRenderer = ({ children }) => {
|
|
30
36
|
const { statusHeight, notificationHeight } = useNotificationHeight();
|
|
37
|
+
const theme = useTheme<BaseThemePropertiesMobile>();
|
|
31
38
|
|
|
32
39
|
const toast = useNotificationToastState();
|
|
33
40
|
|
|
@@ -36,15 +43,22 @@ export const NotificationToastRenderer = ({ children }) => {
|
|
|
36
43
|
|
|
37
44
|
const yPosition = useRef(new Animated.Value(0)).current;
|
|
38
45
|
|
|
39
|
-
const
|
|
40
|
-
|
|
46
|
+
const resolvedStyle =
|
|
47
|
+
toast?.source === CONFIRMATION_TOAST_SOURCE
|
|
48
|
+
? resolveConfirmationToastStyle(theme, toast.style)
|
|
49
|
+
: toast?.style;
|
|
50
|
+
|
|
51
|
+
const backgroundColor =
|
|
52
|
+
resolvedStyle?.backgroundColor ?? DEFAULT_TOAST_BACKGROUND_COLOR;
|
|
53
|
+
|
|
54
|
+
const color = resolvedStyle?.color ?? DEFAULT_TOAST_MESSAGE_COLOR;
|
|
41
55
|
|
|
42
56
|
const textStyles = {
|
|
43
57
|
color,
|
|
44
|
-
fontFamily:
|
|
45
|
-
fontSize:
|
|
46
|
-
lineHeight:
|
|
47
|
-
letterSpacing:
|
|
58
|
+
fontFamily: resolvedStyle?.fontFamily,
|
|
59
|
+
fontSize: resolvedStyle?.fontSize,
|
|
60
|
+
lineHeight: resolvedStyle?.lineHeight,
|
|
61
|
+
letterSpacing: resolvedStyle?.letterSpacing,
|
|
48
62
|
};
|
|
49
63
|
|
|
50
64
|
const animatedViewStyles: ViewStyle = {
|
|
@@ -64,6 +78,20 @@ export const NotificationToastRenderer = ({ children }) => {
|
|
|
64
78
|
backgroundColor,
|
|
65
79
|
};
|
|
66
80
|
|
|
81
|
+
const flingGesture = useMemo(
|
|
82
|
+
() =>
|
|
83
|
+
Gesture.Fling()
|
|
84
|
+
.direction(Directions.UP)
|
|
85
|
+
.enabled(!!toast)
|
|
86
|
+
.runOnJS(true)
|
|
87
|
+
.onEnd((_event, success) => {
|
|
88
|
+
if (success) {
|
|
89
|
+
notificationToastManager.dismiss();
|
|
90
|
+
}
|
|
91
|
+
}),
|
|
92
|
+
[toast]
|
|
93
|
+
);
|
|
94
|
+
|
|
67
95
|
useEffect(() => {
|
|
68
96
|
if (toast) {
|
|
69
97
|
setNotificationOpacity(1);
|
|
@@ -83,20 +111,24 @@ export const NotificationToastRenderer = ({ children }) => {
|
|
|
83
111
|
}, [toast]);
|
|
84
112
|
|
|
85
113
|
return (
|
|
86
|
-
<View
|
|
114
|
+
<View
|
|
115
|
+
testID="NotificationToastRenderer"
|
|
116
|
+
style={StyleSheet.absoluteFill}
|
|
117
|
+
pointerEvents="box-none"
|
|
118
|
+
>
|
|
87
119
|
{children}
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
<GestureDetector gesture={flingGesture}>
|
|
121
|
+
<Animated.View
|
|
122
|
+
testID="NotificationToastRenderer-fling"
|
|
123
|
+
pointerEvents={toast ? "auto" : "none"}
|
|
124
|
+
style={animatedViewStyles}
|
|
125
|
+
>
|
|
94
126
|
<View style={{ height: statusHeight, backgroundColor }} />
|
|
95
127
|
<Text testID="NotificationToastRenderer-message" style={textStyles}>
|
|
96
128
|
{toast?.message}
|
|
97
129
|
</Text>
|
|
98
130
|
</Animated.View>
|
|
99
|
-
</
|
|
131
|
+
</GestureDetector>
|
|
100
132
|
</View>
|
|
101
133
|
);
|
|
102
134
|
};
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
notificationToastManager,
|
|
3
3
|
NOTIFICATION_TOAST_EVENTS,
|
|
4
|
+
DEFAULT_TOAST_TIMEOUT,
|
|
4
5
|
} from "../NotificationToastManager";
|
|
5
6
|
import { postEvent } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
|
|
6
7
|
|
|
@@ -210,4 +211,27 @@ describe("NotificationToastManager", () => {
|
|
|
210
211
|
|
|
211
212
|
expect(onShow).not.toHaveBeenCalled();
|
|
212
213
|
});
|
|
214
|
+
|
|
215
|
+
it("defaults timeout to DEFAULT_TOAST_TIMEOUT (4000ms) when omitted and auto-hides", () => {
|
|
216
|
+
const onShow = jest.fn();
|
|
217
|
+
const onHide = jest.fn();
|
|
218
|
+
on(NOTIFICATION_TOAST_EVENTS.SHOW, onShow);
|
|
219
|
+
on(NOTIFICATION_TOAST_EVENTS.HIDE, onHide);
|
|
220
|
+
|
|
221
|
+
notificationToastManager.showToast({
|
|
222
|
+
message: "Added to queue",
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(onShow).toHaveBeenCalledWith(
|
|
226
|
+
expect.objectContaining({
|
|
227
|
+
message: "Added to queue",
|
|
228
|
+
timeout: DEFAULT_TOAST_TIMEOUT,
|
|
229
|
+
}),
|
|
230
|
+
expect.any(Function)
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
jest.advanceTimersByTime(DEFAULT_TOAST_TIMEOUT);
|
|
234
|
+
|
|
235
|
+
expect(onHide).toHaveBeenCalledTimes(1);
|
|
236
|
+
});
|
|
213
237
|
});
|