@applicaster/quick-brick-core 16.0.0-rc.9 → 16.0.0-rc.91
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/ActionsProvider/ActionsProvider.tsx +31 -9
- package/App/ActionsProvider/LegacyActionsRegistryAdapter.tsx +107 -0
- 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 +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/NavigationProvider/NavigationProvider.tsx +51 -1
- package/App/NavigationProvider/__tests__/utils.test.ts +31 -1
- package/App/NavigationProvider/utils.ts +14 -0
- package/App/NotificationToastRenderer/NotificationToastManager.ts +214 -0
- package/App/NotificationToastRenderer/NotificationToastRenderer.tsx +134 -0
- package/App/NotificationToastRenderer/NotificationToastRenderer.tv.tsx +10 -0
- package/App/NotificationToastRenderer/NotificationToastRenderer.web.tsx +61 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastManager.test.ts +237 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.test.tsx +233 -0
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.web.test.tsx +90 -0
- package/App/NotificationToastRenderer/__tests__/resolveConfirmationToastStyle.test.ts +118 -0
- package/App/NotificationToastRenderer/__tests__/useNotificationHeight.test.tsx +58 -0
- package/App/NotificationToastRenderer/__tests__/useNotificationToastState.test.ts +112 -0
- package/App/NotificationToastRenderer/index.tsx +9 -0
- package/App/NotificationToastRenderer/resolveConfirmationToastStyle.ts +33 -0
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +14 -0
- package/App/NotificationToastRenderer/useNotificationToastState.tsx +12 -0
- package/App/index.tsx +8 -5
- package/package.json +8 -8
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import { act, fireEvent, render } from "@testing-library/react-native";
|
|
4
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CONFIRMATION_TOAST_SOURCE,
|
|
8
|
+
notificationToastManager,
|
|
9
|
+
} from "../NotificationToastManager";
|
|
10
|
+
import { NotificationToastRenderer } from "../NotificationToastRenderer";
|
|
11
|
+
|
|
12
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
13
|
+
useSafeAreaInsets: () => ({ top: 44 }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
|
|
17
|
+
useTheme: jest.fn(),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.mock("react-native-gesture-handler", () => {
|
|
21
|
+
const RN = require("react-native");
|
|
22
|
+
const ReactActual = require("react");
|
|
23
|
+
const actual = jest.requireActual("react-native-gesture-handler");
|
|
24
|
+
|
|
25
|
+
const GestureDetector = ReactActual.forwardRef(
|
|
26
|
+
({ gesture, children }: any, ref: any) => {
|
|
27
|
+
const onEnd = gesture?.handlers?.onEnd;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<RN.View
|
|
31
|
+
ref={ref}
|
|
32
|
+
testID="NotificationToastRenderer-fling-handler"
|
|
33
|
+
accessibilityState={{ disabled: gesture?.config?.enabled === false }}
|
|
34
|
+
// drive Gesture.Fling().onEnd via a test-only event
|
|
35
|
+
onEnd={() => onEnd?.({}, true)}
|
|
36
|
+
onEndFailed={() => onEnd?.({}, false)}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</RN.View>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
__esModule: true,
|
|
46
|
+
...actual,
|
|
47
|
+
GestureDetector,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const mockedUseTheme = useTheme as jest.MockedFunction<typeof useTheme>;
|
|
52
|
+
|
|
53
|
+
const confirmationTheme: Partial<BaseThemePropertiesMobile> = {
|
|
54
|
+
confirmation_toast_style_background_color: "#0188FF",
|
|
55
|
+
confirmation_toast_style_color: "#EFEFEF",
|
|
56
|
+
confirmation_toast_style_ios_font_family: "SFProText-Semibold",
|
|
57
|
+
confirmation_toast_style_android_font_family: "Roboto-Medium",
|
|
58
|
+
confirmation_toast_style_ios_font_size: 14,
|
|
59
|
+
confirmation_toast_style_android_font_size: 14,
|
|
60
|
+
confirmation_toast_style_ios_line_height: 44,
|
|
61
|
+
confirmation_toast_style_android_line_height: 44,
|
|
62
|
+
confirmation_toast_style_ios_letter_spacing: -1.4,
|
|
63
|
+
confirmation_toast_style_android_letter_spacing: -1.4,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe("NotificationToastRenderer", () => {
|
|
67
|
+
beforeAll(() => {
|
|
68
|
+
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterAll(() => {
|
|
72
|
+
(console.log as jest.Mock).mockRestore();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
mockedUseTheme.mockReturnValue(
|
|
77
|
+
confirmationTheme as BaseThemePropertiesMobile
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
afterEach(() => {
|
|
82
|
+
// drain whatever is left showing/queued so the next test starts clean
|
|
83
|
+
for (let i = 0; i < 10; i++) {
|
|
84
|
+
notificationToastManager.dismiss();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
jest.restoreAllMocks();
|
|
88
|
+
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("renders its children", () => {
|
|
92
|
+
const { getByText } = render(
|
|
93
|
+
<NotificationToastRenderer>
|
|
94
|
+
<Text>child content</Text>
|
|
95
|
+
</NotificationToastRenderer>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(getByText("child content")).toBeTruthy();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("shows no message before any toast is emitted", () => {
|
|
102
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
getByTestId("NotificationToastRenderer-message").props.children
|
|
106
|
+
).toBeUndefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("displays the message from a toast emitted by the manager", () => {
|
|
110
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
111
|
+
|
|
112
|
+
act(() => {
|
|
113
|
+
notificationToastManager.showToast({ message: "You are offline" });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
getByTestId("NotificationToastRenderer-message").props.children
|
|
118
|
+
).toBe("You are offline");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("applies the toast's style to the message text", () => {
|
|
122
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
123
|
+
|
|
124
|
+
act(() => {
|
|
125
|
+
notificationToastManager.showToast({
|
|
126
|
+
message: "styled",
|
|
127
|
+
style: { color: "#123456", fontSize: 20 },
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(
|
|
132
|
+
getByTestId("NotificationToastRenderer-message").props.style
|
|
133
|
+
).toEqual(expect.objectContaining({ color: "#123456", fontSize: 20 }));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("applies Theme confirmation styles when source is confirmation", () => {
|
|
137
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
notificationToastManager.showToast({
|
|
141
|
+
message: "Added to queue",
|
|
142
|
+
source: CONFIRMATION_TOAST_SOURCE,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(
|
|
147
|
+
getByTestId("NotificationToastRenderer-message").props.style
|
|
148
|
+
).toEqual(
|
|
149
|
+
expect.objectContaining({
|
|
150
|
+
color: "#EFEFEF",
|
|
151
|
+
fontSize: 14,
|
|
152
|
+
lineHeight: 44,
|
|
153
|
+
letterSpacing: -1.4,
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("shallow-merges style overrides onto Theme confirmation defaults", () => {
|
|
159
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
160
|
+
|
|
161
|
+
act(() => {
|
|
162
|
+
notificationToastManager.showToast({
|
|
163
|
+
message: "Playlist created",
|
|
164
|
+
source: CONFIRMATION_TOAST_SOURCE,
|
|
165
|
+
style: { backgroundColor: "#00FF00", fontSize: 20 },
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(
|
|
170
|
+
getByTestId("NotificationToastRenderer-message").props.style
|
|
171
|
+
).toEqual(
|
|
172
|
+
expect.objectContaining({
|
|
173
|
+
color: "#EFEFEF",
|
|
174
|
+
fontSize: 20,
|
|
175
|
+
lineHeight: 44,
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("does not apply Theme confirmation styles for non-confirmation toasts", () => {
|
|
181
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
182
|
+
|
|
183
|
+
act(() => {
|
|
184
|
+
notificationToastManager.showToast({
|
|
185
|
+
message: "You are offline",
|
|
186
|
+
style: { color: "#abcdef" },
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(
|
|
191
|
+
getByTestId("NotificationToastRenderer-message").props.style
|
|
192
|
+
).toEqual(
|
|
193
|
+
expect.objectContaining({
|
|
194
|
+
color: "#abcdef",
|
|
195
|
+
})
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
expect(
|
|
199
|
+
getByTestId("NotificationToastRenderer-message").props.style.fontSize
|
|
200
|
+
).toBeUndefined();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("dismisses the toast on a successful upward fling", () => {
|
|
204
|
+
const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
|
|
205
|
+
|
|
206
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
207
|
+
|
|
208
|
+
act(() => {
|
|
209
|
+
notificationToastManager.showToast({ message: "Added to queue" });
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
fireEvent(getByTestId("NotificationToastRenderer-fling-handler"), "end");
|
|
213
|
+
|
|
214
|
+
expect(dismissSpy).toHaveBeenCalled();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("does not dismiss when the fling ends unsuccessfully", () => {
|
|
218
|
+
const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
|
|
219
|
+
|
|
220
|
+
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
221
|
+
|
|
222
|
+
act(() => {
|
|
223
|
+
notificationToastManager.showToast({ message: "Added to queue" });
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
fireEvent(
|
|
227
|
+
getByTestId("NotificationToastRenderer-fling-handler"),
|
|
228
|
+
"endFailed"
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
expect(dismissSpy).not.toHaveBeenCalled();
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -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,118 @@
|
|
|
1
|
+
import { resolveConfirmationToastStyle } from "../resolveConfirmationToastStyle";
|
|
2
|
+
|
|
3
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
|
|
4
|
+
// manifestKeyParser captures currentPlatform at module load from this map
|
|
5
|
+
platformSelect: jest.fn((platforms) => {
|
|
6
|
+
if (platforms?.ios === "ios" && platforms?.android === "android") {
|
|
7
|
+
return "ios";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return platforms?.default;
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe("resolveConfirmationToastStyle", () => {
|
|
15
|
+
const theme = {
|
|
16
|
+
confirmation_toast_style_background_color: "#0188FF",
|
|
17
|
+
confirmation_toast_style_color: "#EFEFEF",
|
|
18
|
+
confirmation_toast_style_ios_font_family: "SFProText-Semibold",
|
|
19
|
+
confirmation_toast_style_android_font_family: "Roboto-Medium",
|
|
20
|
+
confirmation_toast_style_ios_font_size: 14,
|
|
21
|
+
confirmation_toast_style_android_font_size: 16,
|
|
22
|
+
confirmation_toast_style_ios_line_height: 44,
|
|
23
|
+
confirmation_toast_style_android_line_height: 40,
|
|
24
|
+
confirmation_toast_style_ios_letter_spacing: -1.4,
|
|
25
|
+
confirmation_toast_style_android_letter_spacing: -0.5,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
it("maps Theme confirmation_toast_style_* keys via getAllSpecificStyles (iOS platform)", () => {
|
|
29
|
+
expect(resolveConfirmationToastStyle(theme)).toEqual({
|
|
30
|
+
backgroundColor: "#0188FF",
|
|
31
|
+
color: "#EFEFEF",
|
|
32
|
+
fontFamily: "SFProText-Semibold",
|
|
33
|
+
fontSize: 14,
|
|
34
|
+
lineHeight: 44,
|
|
35
|
+
letterSpacing: -1.4,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("ignores other-platform keys for the current platform", () => {
|
|
40
|
+
const result = resolveConfirmationToastStyle(theme);
|
|
41
|
+
|
|
42
|
+
expect(result.fontFamily).toBe("SFProText-Semibold");
|
|
43
|
+
expect(result.fontSize).toBe(14);
|
|
44
|
+
|
|
45
|
+
expect(result).not.toEqual(
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
fontFamily: "Roboto-Medium",
|
|
48
|
+
fontSize: 16,
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("shallow-merges override style on top of Theme defaults", () => {
|
|
54
|
+
expect(
|
|
55
|
+
resolveConfirmationToastStyle(theme, {
|
|
56
|
+
backgroundColor: "#00FF00",
|
|
57
|
+
fontSize: 20,
|
|
58
|
+
})
|
|
59
|
+
).toEqual({
|
|
60
|
+
backgroundColor: "#00FF00",
|
|
61
|
+
color: "#EFEFEF",
|
|
62
|
+
fontFamily: "SFProText-Semibold",
|
|
63
|
+
fontSize: 20,
|
|
64
|
+
lineHeight: 44,
|
|
65
|
+
letterSpacing: -1.4,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns override fields when Theme is missing", () => {
|
|
70
|
+
expect(resolveConfirmationToastStyle(undefined, { color: "#fff" })).toEqual(
|
|
71
|
+
{
|
|
72
|
+
color: "#fff",
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("resolveConfirmationToastStyle (android platform)", () => {
|
|
79
|
+
it("maps android platform Theme keys", () => {
|
|
80
|
+
jest.resetModules();
|
|
81
|
+
|
|
82
|
+
jest.doMock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
|
|
83
|
+
platformSelect: jest.fn((platforms) => {
|
|
84
|
+
if (platforms?.ios === "ios" && platforms?.android === "android") {
|
|
85
|
+
return "android";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return platforms?.default;
|
|
89
|
+
}),
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const {
|
|
93
|
+
resolveConfirmationToastStyle: resolveAndroid,
|
|
94
|
+
} = require("../resolveConfirmationToastStyle");
|
|
95
|
+
|
|
96
|
+
const theme = {
|
|
97
|
+
confirmation_toast_style_background_color: "#0188FF",
|
|
98
|
+
confirmation_toast_style_color: "#EFEFEF",
|
|
99
|
+
confirmation_toast_style_ios_font_family: "SFProText-Semibold",
|
|
100
|
+
confirmation_toast_style_android_font_family: "Roboto-Medium",
|
|
101
|
+
confirmation_toast_style_ios_font_size: 14,
|
|
102
|
+
confirmation_toast_style_android_font_size: 16,
|
|
103
|
+
confirmation_toast_style_ios_line_height: 44,
|
|
104
|
+
confirmation_toast_style_android_line_height: 40,
|
|
105
|
+
confirmation_toast_style_ios_letter_spacing: -1.4,
|
|
106
|
+
confirmation_toast_style_android_letter_spacing: -0.5,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
expect(resolveAndroid(theme)).toEqual({
|
|
110
|
+
backgroundColor: "#0188FF",
|
|
111
|
+
color: "#EFEFEF",
|
|
112
|
+
fontFamily: "Roboto-Medium",
|
|
113
|
+
fontSize: 16,
|
|
114
|
+
lineHeight: 40,
|
|
115
|
+
letterSpacing: -0.5,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
let mockInsets = { top: 0 };
|
|
4
|
+
const mockGetNavbarHeight = jest.fn();
|
|
5
|
+
|
|
6
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
7
|
+
useSafeAreaInsets: () => mockInsets,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/layout", () => ({
|
|
11
|
+
getNavbarHeight: () => mockGetNavbarHeight(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
import { useNotificationHeight } from "../useNotificationHeight";
|
|
15
|
+
|
|
16
|
+
describe("useNotificationHeight", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockGetNavbarHeight.mockClear();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("adds the safe area top inset to the nav bar height", () => {
|
|
22
|
+
mockInsets = { top: 44 };
|
|
23
|
+
mockGetNavbarHeight.mockReturnValueOnce(56);
|
|
24
|
+
|
|
25
|
+
const { result } = renderHook(() => useNotificationHeight());
|
|
26
|
+
|
|
27
|
+
expect(result.current).toEqual({
|
|
28
|
+
statusHeight: 44,
|
|
29
|
+
notificationHeight: 100,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("falls back to a 0 status height when there is no top inset", () => {
|
|
34
|
+
mockInsets = { top: 0 };
|
|
35
|
+
mockGetNavbarHeight.mockReturnValueOnce(44);
|
|
36
|
+
|
|
37
|
+
const { result } = renderHook(() => useNotificationHeight());
|
|
38
|
+
|
|
39
|
+
expect(result.current).toEqual({
|
|
40
|
+
statusHeight: 0,
|
|
41
|
+
notificationHeight: 44,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("uses getNavbarHeight for the nav bar height", () => {
|
|
46
|
+
mockInsets = { top: 20 };
|
|
47
|
+
mockGetNavbarHeight.mockReturnValueOnce(56);
|
|
48
|
+
|
|
49
|
+
const { result } = renderHook(() => useNotificationHeight());
|
|
50
|
+
|
|
51
|
+
expect(mockGetNavbarHeight).toHaveBeenCalled();
|
|
52
|
+
|
|
53
|
+
expect(result.current).toEqual({
|
|
54
|
+
statusHeight: 20,
|
|
55
|
+
notificationHeight: 76,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -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,9 @@
|
|
|
1
|
+
export { notificationToastManager } from "./NotificationToastManager";
|
|
2
|
+
|
|
3
|
+
export type { ToastPayload, ToastStyle } from "./NotificationToastManager";
|
|
4
|
+
|
|
5
|
+
export { CONFIRMATION_TOAST_SOURCE } from "./NotificationToastManager";
|
|
6
|
+
|
|
7
|
+
export { NotificationToastRenderer } from "./NotificationToastRenderer";
|
|
8
|
+
|
|
9
|
+
export { resolveConfirmationToastStyle } from "./resolveConfirmationToastStyle";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getAllSpecificStyles } from "@applicaster/zapp-react-native-utils/configurationUtils/manifestKeyParser";
|
|
2
|
+
|
|
3
|
+
import { ToastStyle } from "./NotificationToastManager";
|
|
4
|
+
|
|
5
|
+
const CONFIRMATION_TOAST_STYLE_COMPONENT = "confirmation_toast";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds confirmation-toast style from Theme defaults via getAllSpecificStyles,
|
|
9
|
+
* then shallow-merges any caller override on top.
|
|
10
|
+
*
|
|
11
|
+
* Expected Theme keys follow:
|
|
12
|
+
* `confirmation_toast_style_[platform_]<style_name>`
|
|
13
|
+
* e.g. confirmation_toast_style_background_color,
|
|
14
|
+
* confirmation_toast_style_ios_font_family
|
|
15
|
+
*/
|
|
16
|
+
export function resolveConfirmationToastStyle(
|
|
17
|
+
theme: Partial<BaseThemePropertiesMobile> | null | undefined,
|
|
18
|
+
overrideStyle?: ToastStyle | null
|
|
19
|
+
): ToastStyle {
|
|
20
|
+
const outStyles: Record<string, ToastStyle> = {};
|
|
21
|
+
|
|
22
|
+
getAllSpecificStyles({
|
|
23
|
+
configuration: { ...(theme ?? {}) },
|
|
24
|
+
componentName: CONFIRMATION_TOAST_STYLE_COMPONENT,
|
|
25
|
+
subComponentName: "",
|
|
26
|
+
outStyles,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
...outStyles.default,
|
|
31
|
+
...overrideStyle,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
+
import { getNavbarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
|
|
3
|
+
|
|
4
|
+
/** Hook calculates the height of the notification area including the status bar and navigation bar, used only for mobile */
|
|
5
|
+
export const useNotificationHeight = () => {
|
|
6
|
+
const insets = useSafeAreaInsets();
|
|
7
|
+
|
|
8
|
+
const navBarHeight = getNavbarHeight();
|
|
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
|
+
};
|