@applicaster/quick-brick-core 16.0.0-rc.80 → 16.0.0-rc.82
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/ModalProvider/ModalContent.tsx +17 -1
- package/App/ModalProvider/__tests__/ModalContent.test.tsx +44 -0
- package/App/ModalProvider/__tests__/index.test.tsx +75 -0
- package/App/ModalProvider/index.tsx +32 -14
- package/App/NotificationToastRenderer/NotificationToastRenderer.tv.tsx +6 -127
- package/App/NotificationToastRenderer/index.tsx +0 -2
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +1 -0
- package/package.json +8 -8
|
@@ -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
|
-
|
|
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
|
-
|
|
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:
|
|
31
|
-
screenId:
|
|
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
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
}
|
|
@@ -1,131 +1,10 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { View, Text, Animated, StyleSheet, ViewStyle } from "react-native";
|
|
3
|
-
import {
|
|
4
|
-
Directions,
|
|
5
|
-
FlingGestureHandler,
|
|
6
|
-
State,
|
|
7
|
-
} from "react-native-gesture-handler";
|
|
8
|
-
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
1
|
+
import React from "react";
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { useNotificationToastState } from "./useNotificationToastState";
|
|
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";
|
|
20
|
-
|
|
21
|
-
const styles = StyleSheet.create({
|
|
22
|
-
notificationView: {
|
|
23
|
-
flex: 1,
|
|
24
|
-
position: "absolute",
|
|
25
|
-
alignItems: "center",
|
|
26
|
-
justifyContent: "center",
|
|
27
|
-
top: 0,
|
|
28
|
-
left: 0,
|
|
29
|
-
right: 0,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
type NumberBoolean = 0 | 1;
|
|
3
|
+
/**
|
|
4
|
+
* NotificationToastRenderer for TV platforms.
|
|
5
|
+
* Currently, it does not render anything except for the children passed to it.
|
|
6
|
+
*/
|
|
34
7
|
|
|
35
8
|
export const NotificationToastRenderer = ({ children }) => {
|
|
36
|
-
|
|
37
|
-
const theme = useTheme<BaseThemePropertiesMobile>();
|
|
38
|
-
|
|
39
|
-
const toast = useNotificationToastState();
|
|
40
|
-
|
|
41
|
-
const [notificationOpacity, setNotificationOpacity] =
|
|
42
|
-
useState<NumberBoolean>(0);
|
|
43
|
-
|
|
44
|
-
const yPosition = useRef(new Animated.Value(0)).current;
|
|
45
|
-
|
|
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;
|
|
55
|
-
|
|
56
|
-
const textStyles = {
|
|
57
|
-
color,
|
|
58
|
-
fontFamily: resolvedStyle?.fontFamily,
|
|
59
|
-
fontSize: resolvedStyle?.fontSize,
|
|
60
|
-
lineHeight: resolvedStyle?.lineHeight,
|
|
61
|
-
letterSpacing: resolvedStyle?.letterSpacing,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const animatedViewStyles: ViewStyle = {
|
|
65
|
-
...styles.notificationView,
|
|
66
|
-
transform: [
|
|
67
|
-
{
|
|
68
|
-
translateY: yPosition.interpolate({
|
|
69
|
-
inputRange: [0, 1],
|
|
70
|
-
outputRange: [-notificationHeight, 0],
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
opacity: notificationOpacity,
|
|
75
|
-
height: notificationHeight,
|
|
76
|
-
width: "100%",
|
|
77
|
-
|
|
78
|
-
backgroundColor,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const onFlingStateChange = useCallback(({ nativeEvent }) => {
|
|
82
|
-
// Fling activates then ends; dismiss once the upward fling is recognized.
|
|
83
|
-
if (nativeEvent.oldState === State.ACTIVE) {
|
|
84
|
-
notificationToastManager.dismiss();
|
|
85
|
-
}
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (toast) {
|
|
90
|
-
setNotificationOpacity(1);
|
|
91
|
-
|
|
92
|
-
Animated.timing(yPosition, {
|
|
93
|
-
toValue: 1,
|
|
94
|
-
useNativeDriver: true,
|
|
95
|
-
duration: 300,
|
|
96
|
-
}).start();
|
|
97
|
-
} else {
|
|
98
|
-
Animated.timing(yPosition, {
|
|
99
|
-
toValue: 0,
|
|
100
|
-
useNativeDriver: true,
|
|
101
|
-
duration: 300,
|
|
102
|
-
}).start(() => setNotificationOpacity(0));
|
|
103
|
-
}
|
|
104
|
-
}, [toast]);
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<View
|
|
108
|
-
testID="NotificationToastRenderer"
|
|
109
|
-
style={StyleSheet.absoluteFill}
|
|
110
|
-
pointerEvents="box-none"
|
|
111
|
-
>
|
|
112
|
-
{children}
|
|
113
|
-
<FlingGestureHandler
|
|
114
|
-
enabled={!!toast}
|
|
115
|
-
direction={Directions.UP}
|
|
116
|
-
onHandlerStateChange={onFlingStateChange}
|
|
117
|
-
>
|
|
118
|
-
<Animated.View
|
|
119
|
-
testID="NotificationToastRenderer-fling"
|
|
120
|
-
pointerEvents={toast ? "auto" : "none"}
|
|
121
|
-
style={animatedViewStyles}
|
|
122
|
-
>
|
|
123
|
-
<View style={{ height: statusHeight, backgroundColor }} />
|
|
124
|
-
<Text testID="NotificationToastRenderer-message" style={textStyles}>
|
|
125
|
-
{toast?.message}
|
|
126
|
-
</Text>
|
|
127
|
-
</Animated.View>
|
|
128
|
-
</FlingGestureHandler>
|
|
129
|
-
</View>
|
|
130
|
-
);
|
|
9
|
+
return <>{children}</>;
|
|
131
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-rc.
|
|
3
|
+
"version": "16.0.0-rc.82",
|
|
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-rc.
|
|
32
|
-
"@applicaster/quick-brick-core-plugins": "16.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-pipes-v2-client": "16.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.
|
|
35
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-rc.
|
|
36
|
-
"@applicaster/zapp-react-native-ui-components": "16.0.0-rc.
|
|
37
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-rc.82",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "16.0.0-rc.82",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "16.0.0-rc.82",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.82",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-rc.82",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "16.0.0-rc.82",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-rc.82",
|
|
38
38
|
"atob": "^2.1.2",
|
|
39
39
|
"axios": "^0.28.0",
|
|
40
40
|
"btoa": "^1.2.1",
|