@applicaster/quick-brick-core 15.1.6-alpha.3988508055 → 15.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +1 -9
- package/App/NotificationToastRenderer/NotificationToastManager.ts +2 -8
- package/App/NotificationToastRenderer/__tests__/NotificationToastManager.test.ts +0 -24
- package/App/NotificationToastRenderer/__tests__/NotificationToastRenderer.test.tsx +8 -6
- package/App/NotificationToastRenderer/__tests__/useNotificationHeight.test.tsx +11 -16
- package/App/NotificationToastRenderer/useNotificationHeight.tsx +3 -2
- package/App/index.tsx +8 -5
- package/package.json +8 -8
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.android.test.ts +0 -105
- package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.test.ts +0 -102
- package/App/ModalProvider/ModalBottomSheet/hooks/index.ts +0 -1
- package/App/ModalProvider/ModalBottomSheet/hooks/useKeyboardHeight.ts +0 -30
|
@@ -14,8 +14,6 @@ import {
|
|
|
14
14
|
platformSelect,
|
|
15
15
|
} from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
16
16
|
|
|
17
|
-
import { useKeyboardHeight } from "./hooks";
|
|
18
|
-
|
|
19
17
|
type Props = {
|
|
20
18
|
children: React.ReactChild;
|
|
21
19
|
backgroundColor: string;
|
|
@@ -106,8 +104,6 @@ export function ModalBottomSheetFrame(props: Props) {
|
|
|
106
104
|
|
|
107
105
|
const sheetHeight = useGetSheetHeight(height, maxHeight);
|
|
108
106
|
|
|
109
|
-
const keyboardHeight = useKeyboardHeight();
|
|
110
|
-
|
|
111
107
|
return (
|
|
112
108
|
<DraggableBottomSheet
|
|
113
109
|
sheetHeight={sheetHeight}
|
|
@@ -117,11 +113,7 @@ export function ModalBottomSheetFrame(props: Props) {
|
|
|
117
113
|
header={(dragging) => <Handle {...handleProps} focused={dragging} />}
|
|
118
114
|
maxWidth={maxWidth}
|
|
119
115
|
{...dimensions}
|
|
120
|
-
height={
|
|
121
|
-
safeAreaDims.height -
|
|
122
|
-
(Platform.OS === "ios" ? bottom : 0) -
|
|
123
|
-
keyboardHeight
|
|
124
|
-
}
|
|
116
|
+
height={safeAreaDims.height - (Platform.OS === "ios" ? bottom : 0)}
|
|
125
117
|
>
|
|
126
118
|
<SafeAreaView
|
|
127
119
|
edges={["left", "right", "bottom"]}
|
|
@@ -24,13 +24,11 @@ export interface ToastStyle {
|
|
|
24
24
|
letterSpacing?: number;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const DEFAULT_TOAST_TIMEOUT = 4000;
|
|
28
|
-
|
|
29
27
|
export interface ToastPayload {
|
|
30
28
|
id?: string;
|
|
31
29
|
message: string;
|
|
32
30
|
extraMessage?: string; // secondary line; TV renderers show it as a subtitle, mobile ignores it
|
|
33
|
-
timeout?: number; // ms;
|
|
31
|
+
timeout?: number; // ms; if omitted, toast stays until dismissed
|
|
34
32
|
style?: ToastStyle;
|
|
35
33
|
[key: string]: unknown;
|
|
36
34
|
}
|
|
@@ -124,11 +122,7 @@ class NotificationToastManager {
|
|
|
124
122
|
};
|
|
125
123
|
|
|
126
124
|
private handleShowToast = (payload: ToastPayload) => {
|
|
127
|
-
const item = {
|
|
128
|
-
...payload,
|
|
129
|
-
id: payload.id ?? String(this.nextId++),
|
|
130
|
-
timeout: payload.timeout ?? DEFAULT_TOAST_TIMEOUT,
|
|
131
|
-
};
|
|
125
|
+
const item = { ...payload, id: payload.id ?? String(this.nextId++) };
|
|
132
126
|
|
|
133
127
|
const queuedIndex = this.queue.findIndex((queued) => queued.id === item.id);
|
|
134
128
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
notificationToastManager,
|
|
3
3
|
NOTIFICATION_TOAST_EVENTS,
|
|
4
|
-
DEFAULT_TOAST_TIMEOUT,
|
|
5
4
|
} from "../NotificationToastManager";
|
|
6
5
|
import { postEvent } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
|
|
7
6
|
|
|
@@ -211,27 +210,4 @@ describe("NotificationToastManager", () => {
|
|
|
211
210
|
|
|
212
211
|
expect(onShow).not.toHaveBeenCalled();
|
|
213
212
|
});
|
|
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
|
-
});
|
|
237
213
|
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Text } from "react-native";
|
|
3
|
-
import { act, fireEvent
|
|
3
|
+
import { act, fireEvent } from "@testing-library/react-native";
|
|
4
|
+
import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
4
5
|
|
|
5
6
|
import { notificationToastManager } from "../NotificationToastManager";
|
|
6
7
|
import { NotificationToastRenderer } from "../NotificationToastRenderer";
|
|
7
8
|
|
|
8
9
|
jest.mock("react-native-safe-area-context", () => ({
|
|
10
|
+
...jest.requireActual("react-native-safe-area-context"),
|
|
9
11
|
useSafeAreaInsets: () => ({ top: 44 }),
|
|
10
12
|
}));
|
|
11
13
|
|
|
@@ -29,7 +31,7 @@ describe("NotificationToastRenderer", () => {
|
|
|
29
31
|
});
|
|
30
32
|
|
|
31
33
|
it("renders its children", () => {
|
|
32
|
-
const { getByText } =
|
|
34
|
+
const { getByText } = renderWithProviders(
|
|
33
35
|
<NotificationToastRenderer>
|
|
34
36
|
<Text>child content</Text>
|
|
35
37
|
</NotificationToastRenderer>
|
|
@@ -39,7 +41,7 @@ describe("NotificationToastRenderer", () => {
|
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
it("shows no message before any toast is emitted", () => {
|
|
42
|
-
const { getByTestId } =
|
|
44
|
+
const { getByTestId } = renderWithProviders(<NotificationToastRenderer />);
|
|
43
45
|
|
|
44
46
|
expect(
|
|
45
47
|
getByTestId("NotificationToastRenderer-message").props.children
|
|
@@ -47,7 +49,7 @@ describe("NotificationToastRenderer", () => {
|
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
it("displays the message from a toast emitted by the manager", () => {
|
|
50
|
-
const { getByTestId } =
|
|
52
|
+
const { getByTestId } = renderWithProviders(<NotificationToastRenderer />);
|
|
51
53
|
|
|
52
54
|
act(() => {
|
|
53
55
|
notificationToastManager.showToast({ message: "You are offline" });
|
|
@@ -59,7 +61,7 @@ describe("NotificationToastRenderer", () => {
|
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
it("applies the toast's style to the message text", () => {
|
|
62
|
-
const { getByTestId } =
|
|
64
|
+
const { getByTestId } = renderWithProviders(<NotificationToastRenderer />);
|
|
63
65
|
|
|
64
66
|
act(() => {
|
|
65
67
|
notificationToastManager.showToast({
|
|
@@ -76,7 +78,7 @@ describe("NotificationToastRenderer", () => {
|
|
|
76
78
|
it("dismisses the toast when the touchable area is pressed", () => {
|
|
77
79
|
const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
|
|
78
80
|
|
|
79
|
-
const { getByTestId } =
|
|
81
|
+
const { getByTestId } = renderWithProviders(<NotificationToastRenderer />);
|
|
80
82
|
|
|
81
83
|
fireEvent.press(getByTestId("NotificationToastRenderer-touchable"));
|
|
82
84
|
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-native";
|
|
2
2
|
|
|
3
3
|
let mockInsets = { top: 0 };
|
|
4
|
-
const mockGetNavbarHeight = jest.fn();
|
|
5
4
|
|
|
6
5
|
jest.mock("react-native-safe-area-context", () => ({
|
|
7
6
|
useSafeAreaInsets: () => mockInsets,
|
|
8
7
|
}));
|
|
9
8
|
|
|
10
|
-
jest.mock("@applicaster/zapp-react-native-utils/
|
|
11
|
-
|
|
9
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
|
|
10
|
+
...jest.requireActual("@applicaster/zapp-react-native-utils/reactUtils"),
|
|
11
|
+
platformSelect: jest.fn(({ ios, android }) => ({ ios, android })),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
+
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
14
15
|
import { useNotificationHeight } from "../useNotificationHeight";
|
|
15
16
|
|
|
16
17
|
describe("useNotificationHeight", () => {
|
|
17
18
|
beforeEach(() => {
|
|
18
|
-
|
|
19
|
+
(platformSelect as jest.Mock).mockClear();
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
it("adds the safe area top inset to the nav bar height", () => {
|
|
22
|
+
it("adds the safe area top inset to the platform nav bar height", () => {
|
|
22
23
|
mockInsets = { top: 44 };
|
|
23
|
-
|
|
24
|
+
(platformSelect as jest.Mock).mockReturnValueOnce(56);
|
|
24
25
|
|
|
25
26
|
const { result } = renderHook(() => useNotificationHeight());
|
|
26
27
|
|
|
@@ -32,7 +33,7 @@ describe("useNotificationHeight", () => {
|
|
|
32
33
|
|
|
33
34
|
it("falls back to a 0 status height when there is no top inset", () => {
|
|
34
35
|
mockInsets = { top: 0 };
|
|
35
|
-
|
|
36
|
+
(platformSelect as jest.Mock).mockReturnValueOnce(44);
|
|
36
37
|
|
|
37
38
|
const { result } = renderHook(() => useNotificationHeight());
|
|
38
39
|
|
|
@@ -42,17 +43,11 @@ describe("useNotificationHeight", () => {
|
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
it("
|
|
46
|
+
it("selects the nav bar height per platform via platformSelect", () => {
|
|
46
47
|
mockInsets = { top: 20 };
|
|
47
|
-
mockGetNavbarHeight.mockReturnValueOnce(56);
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(mockGetNavbarHeight).toHaveBeenCalled();
|
|
49
|
+
renderHook(() => useNotificationHeight());
|
|
52
50
|
|
|
53
|
-
expect(
|
|
54
|
-
statusHeight: 20,
|
|
55
|
-
notificationHeight: 76,
|
|
56
|
-
});
|
|
51
|
+
expect(platformSelect).toHaveBeenCalledWith({ ios: 44, android: 56 });
|
|
57
52
|
});
|
|
58
53
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
3
4
|
|
|
4
5
|
export const useNotificationHeight = () => {
|
|
5
6
|
const insets = useSafeAreaInsets();
|
|
6
7
|
|
|
7
|
-
const navBarHeight =
|
|
8
|
+
const navBarHeight = platformSelect({ ios: 44, android: 56 });
|
|
8
9
|
|
|
9
10
|
const statusHeight = insets.top;
|
|
10
11
|
const notificationHeight = statusHeight + navBarHeight;
|
package/App/index.tsx
CHANGED
|
@@ -31,6 +31,7 @@ import { withActionExecutor } from "@applicaster/zapp-react-native-utils/actions
|
|
|
31
31
|
import { withScreenDataContextProvider } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
32
32
|
import { LogicAggregatorContainer } from "./LogicAggregatorContainer";
|
|
33
33
|
import { LoadingOverlay } from "./LoadingOverlay";
|
|
34
|
+
import { NotificationToastRenderer } from "./NotificationToastRenderer";
|
|
34
35
|
import { ZappAppWrapper } from "./components/ZappAppWrapper";
|
|
35
36
|
|
|
36
37
|
interface AppOptions {
|
|
@@ -67,11 +68,13 @@ const App = ({
|
|
|
67
68
|
<ErrorBoundary>
|
|
68
69
|
<URLSchemeListener>
|
|
69
70
|
<SplashLoader>
|
|
70
|
-
<
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
<NotificationToastRenderer>
|
|
72
|
+
<OfflineHandler>
|
|
73
|
+
<Layout>
|
|
74
|
+
<RouteManager />
|
|
75
|
+
</Layout>
|
|
76
|
+
</OfflineHandler>
|
|
77
|
+
</NotificationToastRenderer>
|
|
75
78
|
</SplashLoader>
|
|
76
79
|
<ModalProvider />
|
|
77
80
|
</URLSchemeListener>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-core",
|
|
3
|
-
"version": "15.1.6
|
|
3
|
+
"version": "15.1.6",
|
|
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": "15.1.6
|
|
32
|
-
"@applicaster/quick-brick-core-plugins": "15.1.6
|
|
33
|
-
"@applicaster/zapp-pipes-v2-client": "15.1.6
|
|
34
|
-
"@applicaster/zapp-react-native-bridge": "15.1.6
|
|
35
|
-
"@applicaster/zapp-react-native-redux": "15.1.6
|
|
36
|
-
"@applicaster/zapp-react-native-ui-components": "15.1.6
|
|
37
|
-
"@applicaster/zapp-react-native-utils": "15.1.6
|
|
31
|
+
"@applicaster/applicaster-types": "15.1.6",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "15.1.6",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "15.1.6",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "15.1.6",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "15.1.6",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "15.1.6",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "15.1.6",
|
|
38
38
|
"atob": "^2.1.2",
|
|
39
39
|
"axios": "^0.28.0",
|
|
40
40
|
"btoa": "^1.2.1",
|
package/App/ModalProvider/ModalBottomSheet/hooks/__tests__/useKeyboardHeight.android.test.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useKeyboardHeight } from "./useKeyboardHeight";
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|