@applicaster/quick-brick-core 16.0.0-alpha.4115436491 → 16.0.0-alpha.4155601029
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/ActionSetters/index.ts +2 -2
- package/App/ActionsProvider/ActionsProvider.tsx +31 -9
- package/App/ActionsProvider/LegacyActionsRegistryAdapter.tsx +123 -0
- package/App/ActionsProvider/__tests__/LegacyActionsRegistryAdapter.test.tsx +64 -0
- package/App/AssetCache/logger.ts +1 -1
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +25 -15
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/usePresentSchemeHandler.ts +3 -0
- package/App/DeepLinking/URLSchemeListener/URLSchemeContextProvider.tsx +4 -1
- package/App/DeepLinking/logger.ts +1 -1
- package/App/ErrorBoundary/index.tsx +5 -2
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/__tests__/index.test.tsx +88 -0
- package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +30 -56
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +9 -2
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.android.test.ts +105 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.test.ts +102 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/index.ts +1 -0
- package/App/ModalProvider/ModalBottomSheet/hooks/useKeyboardHeight.ts +30 -0
- package/App/ModalProvider/ModalBottomSheet/index.tsx +5 -2
- package/App/ModalProvider/ModalContent.tsx +3 -0
- package/App/ModalProvider/ModalPresenter.tsx +16 -1
- package/App/ModalProvider/__tests__/ModalContent.test.tsx +39 -0
- package/App/ModalProvider/__tests__/ModalPresenter.test.tsx +17 -0
- package/App/ModalProvider/__tests__/index.test.tsx +99 -0
- package/App/ModalProvider/index.tsx +39 -14
- package/App/NavigationProvider/NavigationProvider.tsx +73 -12
- package/App/NavigationProvider/__tests__/navToolbox.test.ts +227 -0
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +56 -0
- package/App/NavigationProvider/__tests__/utils.test.ts +31 -1
- package/App/NavigationProvider/navToolbox.ts +224 -0
- package/App/NavigationProvider/utils.ts +37 -2
- package/App/NetworkStatusProvider/NetworkStatusProvider.tsx +40 -4
- package/App/NetworkStatusProvider/ResumeVerificationController.ts +282 -0
- package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +167 -1
- package/App/NetworkStatusProvider/__tests__/ResumeVerificationController.test.ts +486 -0
- package/App/NetworkStatusProvider/__tests__/resumeVerification.test.ts +126 -0
- package/App/NetworkStatusProvider/__tests__/useResumeVerifiedNetInfo.test.ts +204 -0
- package/App/NetworkStatusProvider/resumeVerification.ts +54 -0
- package/App/NetworkStatusProvider/useResumeVerifiedNetInfo.ts +33 -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/ThemeManager/index.tsx +6 -1
- package/App/appLifeCycleManager/index.tsx +2 -2
- package/App/appRemoteDataLoader/index.tsx +2 -2
- package/App/appRemoteDataLoader/remoteDataLoader.ts +2 -2
- package/App/index.tsx +16 -7
- package/App/layoutPreview/LayoutPreviewReminder.tsx +136 -0
- package/App/layoutPreview/__tests__/persistence.test.ts +63 -0
- package/App/layoutPreview/persistence.ts +228 -0
- package/App/logger.js +2 -2
- package/App/remoteContextReloader/__tests__/getNativeRemoteContextData.test.ts +148 -0
- package/App/remoteContextReloader/__tests__/getPromiseForType.test.js +31 -0
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +107 -29
- package/App/remoteContextReloader/helpers.ts +2 -1
- package/App/uiActions/index.ts +13 -0
- package/App/uiActions/muteUnmute/__tests__/assetResolver.test.ts +226 -0
- package/App/uiActions/muteUnmute/__tests__/binding.test.ts +51 -0
- package/App/uiActions/muteUnmute/__tests__/defaultAssets.test.ts +73 -0
- package/App/uiActions/muteUnmute/__tests__/entryState.test.ts +57 -0
- package/App/uiActions/muteUnmute/__tests__/labelResolver.test.ts +35 -0
- package/App/uiActions/muteUnmute/assetResolver.ts +87 -0
- package/App/uiActions/muteUnmute/assets/action/flavour_1/mute.png +0 -0
- package/App/uiActions/muteUnmute/assets/action/flavour_1/unmute.png +0 -0
- package/App/uiActions/muteUnmute/assets/action/flavour_2/mute.png +0 -0
- package/App/uiActions/muteUnmute/assets/action/flavour_2/unmute.png +0 -0
- package/App/uiActions/muteUnmute/assets/button/flavour_1/mute.png +0 -0
- package/App/uiActions/muteUnmute/assets/button/flavour_1/unmute.png +0 -0
- package/App/uiActions/muteUnmute/assets/button/flavour_2/mute.png +0 -0
- package/App/uiActions/muteUnmute/assets/button/flavour_2/unmute.png +0 -0
- package/App/uiActions/muteUnmute/defaultAssets.ts +33 -0
- package/App/uiActions/muteUnmute/entryState.ts +28 -0
- package/App/uiActions/muteUnmute/index.ts +79 -0
- package/App/uiActions/muteUnmute/labelResolver.ts +15 -0
- package/App/uiActions/muteUnmute/types.ts +18 -0
- package/package.json +8 -8
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import React, { Component,
|
|
1
|
+
import React, { Component, ReactElement } from "react";
|
|
2
2
|
import { Animated, StyleSheet, View, Easing } from "react-native";
|
|
3
3
|
import {
|
|
4
4
|
PanGestureHandler,
|
|
5
|
-
NativeViewGestureHandler,
|
|
6
5
|
State,
|
|
7
6
|
TapGestureHandler,
|
|
8
7
|
} from "react-native-gesture-handler";
|
|
9
8
|
|
|
10
9
|
import { SnapPoints } from "./SnapPoints";
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import {
|
|
11
|
+
BottomSheetContext,
|
|
12
|
+
BottomSheetContextValue,
|
|
13
|
+
} from "@applicaster/zapp-react-native-utils/bottomSheet";
|
|
14
|
+
|
|
15
|
+
// Must stay false: the sheet drives _dragY from old-API PanGestureHandler
|
|
16
|
+
// onGestureEvent props via RN Animated.event. This RNGH version cannot attach
|
|
17
|
+
// a native (useNativeDriver: true) Animated.event to those handlers — it leaks
|
|
18
|
+
// the AnimatedEvent object into the JS event path and throws "Expected
|
|
19
|
+
// onGestureHandlerEvent listener to be a function". Native-threaded dragging
|
|
20
|
+
// needs the full reanimated + Gesture-API migration (tracked separately).
|
|
21
|
+
const USE_NATIVE_DRIVER = false;
|
|
13
22
|
const HEADER_HEIGHT = 44;
|
|
14
23
|
|
|
15
24
|
const ANIMATION_DURATION = 400;
|
|
@@ -24,7 +33,7 @@ const styles = StyleSheet.create({
|
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
type Props = {
|
|
27
|
-
children:
|
|
36
|
+
children: ReactElement;
|
|
28
37
|
header: (boolean) => ReactElement;
|
|
29
38
|
dismiss: () => void;
|
|
30
39
|
visible: boolean;
|
|
@@ -49,35 +58,24 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
49
58
|
_isMounted = false;
|
|
50
59
|
_animatedIn = false;
|
|
51
60
|
_animating = false;
|
|
52
|
-
_lastScrollYValue: number;
|
|
53
|
-
_lastScrollY: Animated.Value;
|
|
54
61
|
_dragY: Animated.Value;
|
|
55
|
-
_reverseLastScrollY: Animated.AnimatedInterpolation<number>;
|
|
56
62
|
_translateYOffset: Animated.Value;
|
|
57
63
|
_translateY: Animated.AnimatedInterpolation<number>;
|
|
58
64
|
_snapPoints: SnapPoints;
|
|
59
65
|
_prevContentHeight = 0;
|
|
66
|
+
_bottomSheetContextValue: BottomSheetContextValue;
|
|
60
67
|
|
|
61
68
|
_callWhenMounted: () => void | null;
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
// One shared JS Animated.event feeds _dragY for every drag handler (top
|
|
71
|
+
// handle, header drag-area, body). Safe because useNativeDriver is false — the
|
|
72
|
+
// event is a plain JS listener that setValue's _dragY for whichever handler
|
|
73
|
+
// is active, and only one gesture is ever active at a time.
|
|
64
74
|
_onGestureEvent: (...args: any[]) => void;
|
|
65
75
|
|
|
66
76
|
constructor(props) {
|
|
67
77
|
super(props);
|
|
68
78
|
|
|
69
|
-
this._lastScrollYValue = 0;
|
|
70
|
-
this._lastScrollY = new Animated.Value(0);
|
|
71
|
-
|
|
72
|
-
this._onRegisterLastScroll = Animated.event(
|
|
73
|
-
[{ nativeEvent: { contentOffset: { y: this._lastScrollY } } }],
|
|
74
|
-
{ useNativeDriver: USE_NATIVE_DRIVER }
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
this._lastScrollY.addListener(({ value }) => {
|
|
78
|
-
this._lastScrollYValue = value;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
79
|
this._dragY = new Animated.Value(0);
|
|
82
80
|
|
|
83
81
|
this._onGestureEvent = Animated.event(
|
|
@@ -85,10 +83,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
85
83
|
{ useNativeDriver: USE_NATIVE_DRIVER }
|
|
86
84
|
);
|
|
87
85
|
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
this.
|
|
91
|
-
|
|
86
|
+
this._bottomSheetContextValue = {
|
|
87
|
+
masterDrawerRef: this.masterdrawer,
|
|
88
|
+
onDragGestureEvent: this._onGestureEvent,
|
|
89
|
+
onDragStateChange: this._onHeaderHandlerStateChange,
|
|
90
|
+
};
|
|
92
91
|
|
|
93
92
|
const initialSnapPoints = new SnapPoints(props.height, props.sheetHeight);
|
|
94
93
|
|
|
@@ -181,7 +180,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
181
180
|
|
|
182
181
|
this._translateY = Animated.add(
|
|
183
182
|
this._translateYOffset,
|
|
184
|
-
|
|
183
|
+
this._dragY
|
|
185
184
|
).interpolate({
|
|
186
185
|
inputRange: [this._snapPoints.top, this._snapPoints.bottom],
|
|
187
186
|
outputRange: [this._snapPoints.top, this._snapPoints.bottom],
|
|
@@ -226,10 +225,6 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
226
225
|
return;
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
if (nativeEvent.oldState === State.BEGAN) {
|
|
230
|
-
this._lastScrollY.setValue(0);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
228
|
this._onHandlerStateChange({ nativeEvent });
|
|
234
229
|
};
|
|
235
230
|
|
|
@@ -240,8 +235,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
240
235
|
|
|
241
236
|
if (nativeEvent.oldState === State.ACTIVE) {
|
|
242
237
|
const { velocityY } = nativeEvent;
|
|
243
|
-
|
|
244
|
-
translationY -= this._lastScrollYValue;
|
|
238
|
+
const { translationY } = nativeEvent;
|
|
245
239
|
const dragToss = 0.05;
|
|
246
240
|
|
|
247
241
|
const endOffsetY =
|
|
@@ -300,7 +294,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
300
294
|
>
|
|
301
295
|
<PanGestureHandler
|
|
302
296
|
ref={this.drawerheader}
|
|
303
|
-
simultaneousHandlers={[this.
|
|
297
|
+
simultaneousHandlers={[this.masterdrawer]}
|
|
304
298
|
shouldCancelWhenOutside={false}
|
|
305
299
|
onGestureEvent={this._onGestureEvent}
|
|
306
300
|
onHandlerStateChange={this._onHeaderHandlerStateChange}
|
|
@@ -309,31 +303,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
|
|
|
309
303
|
{this.props?.header(this.state.dragging)}
|
|
310
304
|
</Animated.View>
|
|
311
305
|
</PanGestureHandler>
|
|
312
|
-
<
|
|
313
|
-
ref={this.drawer}
|
|
314
|
-
simultaneousHandlers={[this.scroll, this.masterdrawer]}
|
|
315
|
-
shouldCancelWhenOutside={false}
|
|
316
|
-
onGestureEvent={this._onGestureEvent}
|
|
317
|
-
onHandlerStateChange={this._onHandlerStateChange}
|
|
318
|
-
>
|
|
306
|
+
<BottomSheetContext.Provider value={this._bottomSheetContextValue}>
|
|
319
307
|
<Animated.View style={styles.container}>
|
|
320
|
-
|
|
321
|
-
ref={this.scroll}
|
|
322
|
-
waitFor={this.masterdrawer}
|
|
323
|
-
simultaneousHandlers={this.drawer}
|
|
324
|
-
>
|
|
325
|
-
<Animated.ScrollView
|
|
326
|
-
bounces={false}
|
|
327
|
-
onScrollBeginDrag={this._onRegisterLastScroll}
|
|
328
|
-
scrollEventThrottle={1}
|
|
329
|
-
scrollEnabled={false}
|
|
330
|
-
showsVerticalScrollIndicator={false}
|
|
331
|
-
>
|
|
332
|
-
{this.props.children}
|
|
333
|
-
</Animated.ScrollView>
|
|
334
|
-
</NativeViewGestureHandler>
|
|
308
|
+
{this.props.children}
|
|
335
309
|
</Animated.View>
|
|
336
|
-
</
|
|
310
|
+
</BottomSheetContext.Provider>
|
|
337
311
|
</Animated.View>
|
|
338
312
|
</View>
|
|
339
313
|
</TapGestureHandler>
|
|
@@ -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
|
/>
|
|
@@ -30,6 +30,9 @@ export function ModalContent(props: Props) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
+
// A presented screen fills the window, including the status bar and home
|
|
34
|
+
// indicator. The modal wraps it in its own SafeAreaProvider, so the screen
|
|
35
|
+
// reads the real insets itself and places its own chrome inside them.
|
|
33
36
|
<View style={styles.container}>
|
|
34
37
|
<ScreenResolver {...modalScreenProps} />
|
|
35
38
|
</View>
|
|
@@ -8,12 +8,27 @@ type Props = ModalProps & {
|
|
|
8
8
|
visible: boolean;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
// RN's iPhone default is portrait only. The player locks the window to
|
|
12
|
+
// landscape before this modal is presented, and UIKit aborts the process
|
|
13
|
+
// when the two masks do not overlap. No JS error is logged.
|
|
14
|
+
const SUPPORTED_ORIENTATIONS: ModalProps["supportedOrientations"] = [
|
|
15
|
+
"portrait",
|
|
16
|
+
"portrait-upside-down",
|
|
17
|
+
"landscape",
|
|
18
|
+
"landscape-left",
|
|
19
|
+
"landscape-right",
|
|
20
|
+
];
|
|
21
|
+
|
|
11
22
|
export function ModalPresenter(props: Props) {
|
|
12
23
|
const { children, ModalContainer, visible, ...presenterOptions } = props;
|
|
13
24
|
const Presenter = React.useMemo(() => ModalContainer || Modal, []);
|
|
14
25
|
|
|
15
26
|
return (
|
|
16
|
-
<Presenter
|
|
27
|
+
<Presenter
|
|
28
|
+
visible={visible}
|
|
29
|
+
{...presenterOptions}
|
|
30
|
+
supportedOrientations={SUPPORTED_ORIENTATIONS}
|
|
31
|
+
>
|
|
17
32
|
<GestureHandlerRootView>{children}</GestureHandlerRootView>
|
|
18
33
|
</Presenter>
|
|
19
34
|
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
|
+
import { ModalContent } from "../ModalContent";
|
|
6
|
+
|
|
7
|
+
jest.mock("../ModalBottomSheet", () => ({ ModalBottomSheet: () => null }));
|
|
8
|
+
|
|
9
|
+
jest.mock(
|
|
10
|
+
"@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
|
|
11
|
+
() => ({ ScreenResolver: () => null })
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const flatStyle = (tree: any) => StyleSheet.flatten(tree.props.style);
|
|
15
|
+
|
|
16
|
+
describe("ModalContent", () => {
|
|
17
|
+
it("lets a presented screen fill the modal, leaving the safe area to the screen", () => {
|
|
18
|
+
const tree = render(
|
|
19
|
+
<ModalContent modalScreenProps={{ screenId: "river-1" }} />
|
|
20
|
+
).toJSON();
|
|
21
|
+
|
|
22
|
+
// The modal provides a SafeAreaProvider instead, so the presented screen
|
|
23
|
+
// reads the real insets itself rather than being padded from the outside.
|
|
24
|
+
expect(flatStyle(tree)).toEqual({ flex: 1 });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("leaves a bottom sheet full-bleed", () => {
|
|
28
|
+
const tree = render(
|
|
29
|
+
<ModalContent
|
|
30
|
+
modalScreenProps={{
|
|
31
|
+
screenData: { modalBottomSheetContentProps: { items: [] } },
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
).toJSON();
|
|
35
|
+
|
|
36
|
+
// Bottom sheets anchor to the screen edge and manage their own insets.
|
|
37
|
+
expect(tree).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Modal } from "react-native";
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
|
+
import { ModalPresenter } from "../ModalPresenter";
|
|
6
|
+
|
|
7
|
+
describe("ModalPresenter", () => {
|
|
8
|
+
it("supports landscape so a player rotation does not abort presentation", () => {
|
|
9
|
+
const { UNSAFE_getByType } = render(
|
|
10
|
+
<ModalPresenter visible>{null}</ModalPresenter>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
expect(UNSAFE_getByType(Modal).props.supportedOrientations).toEqual(
|
|
14
|
+
expect.arrayContaining(["portrait", "landscape"])
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import { modalStore } from "@applicaster/zapp-react-native-utils/modalState";
|
|
5
|
+
|
|
6
|
+
import { ModalProvider } from "../";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Records the ScreenDataContext value seen by the presented screen — the
|
|
10
|
+
* context useScreenContext()/useCurrentScreenData() read from.
|
|
11
|
+
*/
|
|
12
|
+
const mockSeenScreenData: any[] = [];
|
|
13
|
+
|
|
14
|
+
/** Records the `initialMetrics` each SafeAreaProvider the modal renders got. */
|
|
15
|
+
const mockSafeAreaProviderMetrics: any[] = [];
|
|
16
|
+
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-ui-components/Components/ScreenResolver",
|
|
19
|
+
() => {
|
|
20
|
+
const ReactLocal = require("react");
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
ScreenDataContext,
|
|
24
|
+
} = require("@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext");
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
ScreenResolver: () => {
|
|
28
|
+
mockSeenScreenData.push(ReactLocal.useContext(ScreenDataContext));
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Needs the navigator + redux to build navbar state; irrelevant to this test.
|
|
37
|
+
jest.mock(
|
|
38
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext",
|
|
39
|
+
() => ({
|
|
40
|
+
ScreenContextProvider: ({ children }: any) => children,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Pulls in the whole Components barrel; only the ScreenResolver branch matters here.
|
|
45
|
+
jest.mock("../ModalBottomSheet", () => ({ ModalBottomSheet: () => null }));
|
|
46
|
+
|
|
47
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
48
|
+
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
|
|
49
|
+
// A modal renders in its own native window, so it needs its own provider
|
|
50
|
+
// seeded with the window metrics; without them insets read as zero inside.
|
|
51
|
+
initialWindowMetrics: { insets: { top: 59, bottom: 34, left: 0, right: 0 } },
|
|
52
|
+
SafeAreaProvider: ({ children, initialMetrics }: any) => {
|
|
53
|
+
mockSafeAreaProviderMetrics.push(initialMetrics);
|
|
54
|
+
|
|
55
|
+
return children;
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
const river = { id: "river-parent-lock", type: "parent_lock" } as any;
|
|
60
|
+
|
|
61
|
+
const entry = { id: "entry-1", type: { value: "video" } } as any;
|
|
62
|
+
|
|
63
|
+
const seen = () => mockSeenScreenData[mockSeenScreenData.length - 1];
|
|
64
|
+
|
|
65
|
+
describe("ModalProvider", () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
mockSeenScreenData.length = 0;
|
|
68
|
+
mockSafeAreaProviderMetrics.length = 0;
|
|
69
|
+
modalStore.getState().dismissModal();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("gives the presented screen its screen and entry through ScreenDataContext", () => {
|
|
73
|
+
modalStore.getState().openModal({ item: river, props: { entry } });
|
|
74
|
+
|
|
75
|
+
render(<ModalProvider />);
|
|
76
|
+
|
|
77
|
+
expect(seen()).toEqual({ screen: river, entry });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("gives the presented screen its screen when presented without an entry", () => {
|
|
81
|
+
modalStore.getState().openModal({ item: river });
|
|
82
|
+
|
|
83
|
+
render(<ModalProvider />);
|
|
84
|
+
|
|
85
|
+
expect(seen()).toMatchObject({ screen: river });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("seeds the presented screen's safe area with the window metrics", () => {
|
|
89
|
+
const { initialWindowMetrics } = require("react-native-safe-area-context");
|
|
90
|
+
|
|
91
|
+
modalStore.getState().openModal({ item: river });
|
|
92
|
+
|
|
93
|
+
render(<ModalProvider />);
|
|
94
|
+
|
|
95
|
+
expect(mockSafeAreaProviderMetrics).toEqual(
|
|
96
|
+
expect.arrayContaining([initialWindowMetrics])
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
});
|