@applicaster/quick-brick-core 16.0.0-alpha.4416921324 → 16.0.0-alpha.4909430115
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/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/NotificationToastRenderer/NotificationToastManager.ts +13 -2
- package/App/NotificationToastRenderer/NotificationToastRenderer.tsx +56 -24
- package/App/NotificationToastRenderer/NotificationToastRenderer.tv.tsx +131 -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 +6 -0
- package/App/NotificationToastRenderer/resolveConfirmationToastStyle.ts +33 -0
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +2 -3
- package/package.json +8 -8
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx
CHANGED
|
@@ -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
|
|
64
|
-
|
|
65
|
-
jest.
|
|
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: () => [{},
|
|
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
|
-
//
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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,
|
|
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={
|
|
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
|
-
{...
|
|
92
|
+
{...restContentProps}
|
|
90
93
|
dismiss={dismiss}
|
|
91
94
|
currentRoute={navigator.currentRoute}
|
|
92
95
|
/>
|
|
@@ -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,131 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "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";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
CONFIRMATION_TOAST_SOURCE,
|
|
12
|
+
notificationToastManager,
|
|
13
|
+
} from "./NotificationToastManager";
|
|
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;
|
|
34
|
+
|
|
35
|
+
export const NotificationToastRenderer = ({ children }) => {
|
|
36
|
+
const { statusHeight, notificationHeight } = useNotificationHeight();
|
|
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
|
+
);
|
|
131
|
+
};
|
|
@@ -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
|
});
|
|
@@ -1,14 +1,68 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Text } from "react-native";
|
|
3
3
|
import { act, fireEvent, render } from "@testing-library/react-native";
|
|
4
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CONFIRMATION_TOAST_SOURCE,
|
|
8
|
+
notificationToastManager,
|
|
9
|
+
} from "../NotificationToastManager";
|
|
6
10
|
import { NotificationToastRenderer } from "../NotificationToastRenderer";
|
|
7
11
|
|
|
8
12
|
jest.mock("react-native-safe-area-context", () => ({
|
|
9
13
|
useSafeAreaInsets: () => ({ top: 44 }),
|
|
10
14
|
}));
|
|
11
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
|
+
|
|
12
66
|
describe("NotificationToastRenderer", () => {
|
|
13
67
|
beforeAll(() => {
|
|
14
68
|
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
@@ -18,6 +72,12 @@ describe("NotificationToastRenderer", () => {
|
|
|
18
72
|
(console.log as jest.Mock).mockRestore();
|
|
19
73
|
});
|
|
20
74
|
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
mockedUseTheme.mockReturnValue(
|
|
77
|
+
confirmationTheme as BaseThemePropertiesMobile
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
21
81
|
afterEach(() => {
|
|
22
82
|
// drain whatever is left showing/queued so the next test starts clean
|
|
23
83
|
for (let i = 0; i < 10; i++) {
|
|
@@ -73,13 +133,101 @@ describe("NotificationToastRenderer", () => {
|
|
|
73
133
|
).toEqual(expect.objectContaining({ color: "#123456", fontSize: 20 }));
|
|
74
134
|
});
|
|
75
135
|
|
|
76
|
-
it("
|
|
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", () => {
|
|
77
204
|
const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
|
|
78
205
|
|
|
79
206
|
const { getByTestId } = render(<NotificationToastRenderer />);
|
|
80
207
|
|
|
81
|
-
|
|
208
|
+
act(() => {
|
|
209
|
+
notificationToastManager.showToast({ message: "Added to queue" });
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
fireEvent(getByTestId("NotificationToastRenderer-fling-handler"), "end");
|
|
82
213
|
|
|
83
214
|
expect(dismissSpy).toHaveBeenCalled();
|
|
84
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
|
+
});
|
|
85
233
|
});
|
|
@@ -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
|
+
});
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-native";
|
|
2
2
|
|
|
3
3
|
let mockInsets = { top: 0 };
|
|
4
|
+
const mockGetNavbarHeight = jest.fn();
|
|
4
5
|
|
|
5
6
|
jest.mock("react-native-safe-area-context", () => ({
|
|
6
7
|
useSafeAreaInsets: () => mockInsets,
|
|
7
8
|
}));
|
|
8
9
|
|
|
9
|
-
jest.mock("@applicaster/zapp-react-native-utils/
|
|
10
|
-
|
|
11
|
-
platformSelect: jest.fn(({ ios, android }) => ({ ios, android })),
|
|
10
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/layout", () => ({
|
|
11
|
+
getNavbarHeight: () => mockGetNavbarHeight(),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
-
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
15
14
|
import { useNotificationHeight } from "../useNotificationHeight";
|
|
16
15
|
|
|
17
16
|
describe("useNotificationHeight", () => {
|
|
18
17
|
beforeEach(() => {
|
|
19
|
-
|
|
18
|
+
mockGetNavbarHeight.mockClear();
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
it("adds the safe area top inset to the
|
|
21
|
+
it("adds the safe area top inset to the nav bar height", () => {
|
|
23
22
|
mockInsets = { top: 44 };
|
|
24
|
-
|
|
23
|
+
mockGetNavbarHeight.mockReturnValueOnce(56);
|
|
25
24
|
|
|
26
25
|
const { result } = renderHook(() => useNotificationHeight());
|
|
27
26
|
|
|
@@ -33,7 +32,7 @@ describe("useNotificationHeight", () => {
|
|
|
33
32
|
|
|
34
33
|
it("falls back to a 0 status height when there is no top inset", () => {
|
|
35
34
|
mockInsets = { top: 0 };
|
|
36
|
-
|
|
35
|
+
mockGetNavbarHeight.mockReturnValueOnce(44);
|
|
37
36
|
|
|
38
37
|
const { result } = renderHook(() => useNotificationHeight());
|
|
39
38
|
|
|
@@ -43,11 +42,17 @@ describe("useNotificationHeight", () => {
|
|
|
43
42
|
});
|
|
44
43
|
});
|
|
45
44
|
|
|
46
|
-
it("
|
|
45
|
+
it("uses getNavbarHeight for the nav bar height", () => {
|
|
47
46
|
mockInsets = { top: 20 };
|
|
47
|
+
mockGetNavbarHeight.mockReturnValueOnce(56);
|
|
48
48
|
|
|
49
|
-
renderHook(() => useNotificationHeight());
|
|
49
|
+
const { result } = renderHook(() => useNotificationHeight());
|
|
50
|
+
|
|
51
|
+
expect(mockGetNavbarHeight).toHaveBeenCalled();
|
|
50
52
|
|
|
51
|
-
expect(
|
|
53
|
+
expect(result.current).toEqual({
|
|
54
|
+
statusHeight: 20,
|
|
55
|
+
notificationHeight: 76,
|
|
56
|
+
});
|
|
52
57
|
});
|
|
53
58
|
});
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { notificationToastManager } from "./NotificationToastManager";
|
|
2
2
|
|
|
3
|
+
export type { ToastPayload, ToastStyle } from "./NotificationToastManager";
|
|
4
|
+
|
|
5
|
+
export { CONFIRMATION_TOAST_SOURCE } from "./NotificationToastManager";
|
|
6
|
+
|
|
3
7
|
export { NotificationToastRenderer } from "./NotificationToastRenderer";
|
|
4
8
|
|
|
5
9
|
export { useNotificationHeight } from "./useNotificationHeight";
|
|
10
|
+
|
|
11
|
+
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
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
-
|
|
3
|
-
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
2
|
+
import { getNavbarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
|
|
4
3
|
|
|
5
4
|
export const useNotificationHeight = () => {
|
|
6
5
|
const insets = useSafeAreaInsets();
|
|
7
6
|
|
|
8
|
-
const navBarHeight =
|
|
7
|
+
const navBarHeight = getNavbarHeight();
|
|
9
8
|
|
|
10
9
|
const statusHeight = insets.top;
|
|
11
10
|
const notificationHeight = statusHeight + navBarHeight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-core",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.4909430115",
|
|
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.
|
|
32
|
-
"@applicaster/quick-brick-core-plugins": "16.0.0-alpha.
|
|
33
|
-
"@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.
|
|
35
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.
|
|
36
|
-
"@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.
|
|
37
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.4909430115",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "16.0.0-alpha.4909430115",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.4909430115",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.4909430115",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.4909430115",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.4909430115",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.4909430115",
|
|
38
38
|
"atob": "^2.1.2",
|
|
39
39
|
"axios": "^0.28.0",
|
|
40
40
|
"btoa": "^1.2.1",
|