@jobber/components-native 0.88.1-JOB-136074-020f532.3 → 0.89.0
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/dist/package.json +2 -2
- package/dist/src/ContentOverlay/ContentOverlay.js +2 -2
- package/dist/src/ContentOverlay/UNSAFE_WrappedModalize.js +23 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/ContentOverlay/ContentOverlay.d.ts +1 -1
- package/dist/types/src/ContentOverlay/UNSAFE_WrappedModalize.d.ts +3 -0
- package/package.json +2 -2
- package/src/ContentOverlay/ContentOverlay.test.tsx +30 -23
- package/src/ContentOverlay/ContentOverlay.tsx +4 -3
- package/src/ContentOverlay/UNSAFE_WrappedModalize.tsx +41 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Modalize } from "react-native-modalize";
|
|
2
|
+
import type { Modalize } from "react-native-modalize";
|
|
3
3
|
import type { ContentOverlayProps } from "./types";
|
|
4
4
|
export declare const ContentOverlay: React.ForwardRefExoticComponent<ContentOverlayProps & React.RefAttributes<{
|
|
5
5
|
open?: Modalize["open"];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { IHandles } from "react-native-modalize/lib/options";
|
|
3
|
+
export declare const UNSAFE_WrappedModalize: React.ForwardRefExoticComponent<Omit<import("react-native-modalize/lib/options").IProps<any> & React.RefAttributes<string | number | boolean | {} | React.ReactPortal | React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | React.ReactNodeArray | undefined>, "ref"> & React.RefAttributes<IHandles>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"react-native-safe-area-context": "^5.4.0",
|
|
95
95
|
"react-native-svg": ">=12.0.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "11776ee31e17536a81a51c143933031f0601a270"
|
|
98
98
|
}
|
|
@@ -4,7 +4,7 @@ import { AccessibilityInfo, View } from "react-native";
|
|
|
4
4
|
import { Host } from "react-native-portalize";
|
|
5
5
|
import type { ReactTestInstance } from "react-test-renderer";
|
|
6
6
|
import { act } from "react-test-renderer";
|
|
7
|
-
import type { ContentOverlayRef, ModalBackgroundColor } from "./
|
|
7
|
+
import type { ContentOverlayRef, ModalBackgroundColor } from "./types";
|
|
8
8
|
import { ContentOverlay } from "./ContentOverlay";
|
|
9
9
|
import { tokens } from "../utils/design";
|
|
10
10
|
import { Button } from "../Button";
|
|
@@ -106,23 +106,30 @@ function renderContentOverlay(
|
|
|
106
106
|
return renderResult;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
function renderAndOpenContentOverlay(
|
|
109
|
+
async function renderAndOpenContentOverlay(
|
|
110
|
+
defaultOptions = getDefaultOptions(),
|
|
111
|
+
) {
|
|
110
112
|
const rendered = renderContentOverlay(defaultOptions);
|
|
111
113
|
|
|
112
114
|
act(() => {
|
|
113
115
|
fireEvent.press(rendered.getByLabelText(defaultOptions.buttonLabel));
|
|
114
116
|
});
|
|
115
117
|
|
|
118
|
+
// Wait for the modal to open asynchronously (due to requestAnimationFrame)
|
|
119
|
+
await waitFor(() => {
|
|
120
|
+
expect(rendered.getByTestId("ATL-Overlay-Header")).toBeDefined();
|
|
121
|
+
});
|
|
122
|
+
|
|
116
123
|
return rendered;
|
|
117
124
|
}
|
|
118
125
|
|
|
119
126
|
describe("when open is called on the content overlay ref", () => {
|
|
120
|
-
it("should open the content overlay, exposing the content to the user", () => {
|
|
127
|
+
it("should open the content overlay, exposing the content to the user", async () => {
|
|
121
128
|
const options: testRendererOptions = {
|
|
122
129
|
...getDefaultOptions(),
|
|
123
130
|
text: "I am text within the content overlay",
|
|
124
131
|
};
|
|
125
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
132
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
126
133
|
|
|
127
134
|
expect(contentOverlayScreen.getByText(options.text)).toBeDefined();
|
|
128
135
|
});
|
|
@@ -135,7 +142,7 @@ describe("when the close button is clicked on an open content overlay", () => {
|
|
|
135
142
|
text: "I am text within the content overlay",
|
|
136
143
|
showDismiss: true,
|
|
137
144
|
};
|
|
138
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
145
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
139
146
|
|
|
140
147
|
act(() => {
|
|
141
148
|
fireEvent.press(
|
|
@@ -156,7 +163,7 @@ describe("when the close button is clicked on an open content overlay with a def
|
|
|
156
163
|
onCloseCallback: jest.fn(),
|
|
157
164
|
showDismiss: true,
|
|
158
165
|
};
|
|
159
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
166
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
160
167
|
|
|
161
168
|
act(() => {
|
|
162
169
|
fireEvent.press(
|
|
@@ -191,7 +198,7 @@ describe("when the content overlay is created with a defined onOpen prop", () =>
|
|
|
191
198
|
...getDefaultOptions(),
|
|
192
199
|
onOpenCallback: jest.fn(),
|
|
193
200
|
};
|
|
194
|
-
renderAndOpenContentOverlay(options);
|
|
201
|
+
await renderAndOpenContentOverlay(options);
|
|
195
202
|
|
|
196
203
|
await waitFor(() => {
|
|
197
204
|
expect(options.onOpenCallback).toHaveBeenCalled();
|
|
@@ -201,25 +208,25 @@ describe("when the content overlay is created with a defined onOpen prop", () =>
|
|
|
201
208
|
});
|
|
202
209
|
|
|
203
210
|
describe("when title prop passed to content overlay", () => {
|
|
204
|
-
it("should set the header title", () => {
|
|
211
|
+
it("should set the header title", async () => {
|
|
205
212
|
const options: testRendererOptions = {
|
|
206
213
|
...getDefaultOptions(),
|
|
207
214
|
title: "Awesome Title",
|
|
208
215
|
};
|
|
209
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
216
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
210
217
|
|
|
211
218
|
expect(contentOverlayScreen.getByText(options.title)).toBeDefined();
|
|
212
219
|
});
|
|
213
220
|
});
|
|
214
221
|
|
|
215
222
|
describe("when accessibilityLabel prop passed to content overlay", () => {
|
|
216
|
-
it("should set the header accessibilityLabel", () => {
|
|
223
|
+
it("should set the header accessibilityLabel", async () => {
|
|
217
224
|
const options: testRendererOptions = {
|
|
218
225
|
...getDefaultOptions(),
|
|
219
226
|
a11yLabel: "Awesome a11y Label",
|
|
220
227
|
showDismiss: true,
|
|
221
228
|
};
|
|
222
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
229
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
223
230
|
|
|
224
231
|
expect(
|
|
225
232
|
contentOverlayScreen.getByLabelText(options.a11yLabel || "ohno"),
|
|
@@ -228,13 +235,13 @@ describe("when accessibilityLabel prop passed to content overlay", () => {
|
|
|
228
235
|
});
|
|
229
236
|
|
|
230
237
|
describe("when accessibilityLabel prop NOT passed to content overlay", () => {
|
|
231
|
-
it("should use default accessibilityLabel", () => {
|
|
238
|
+
it("should use default accessibilityLabel", async () => {
|
|
232
239
|
const options: testRendererOptions = {
|
|
233
240
|
...getDefaultOptions(),
|
|
234
241
|
title: "Awesome Title",
|
|
235
242
|
showDismiss: true,
|
|
236
243
|
};
|
|
237
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
244
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
238
245
|
|
|
239
246
|
expect(
|
|
240
247
|
contentOverlayScreen.getAllByLabelText(`Close ${options.title} modal`),
|
|
@@ -251,7 +258,7 @@ describe("when there is a screen reader enabled", () => {
|
|
|
251
258
|
const options: testRendererOptions = {
|
|
252
259
|
...getDefaultOptions(),
|
|
253
260
|
};
|
|
254
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
261
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
255
262
|
|
|
256
263
|
expect(
|
|
257
264
|
await contentOverlayScreen.findByTestId("ATL-Overlay-CloseButton"),
|
|
@@ -260,12 +267,12 @@ describe("when there is a screen reader enabled", () => {
|
|
|
260
267
|
});
|
|
261
268
|
|
|
262
269
|
describe("when fullScreen is set to true", () => {
|
|
263
|
-
it("should show the dismiss button", () => {
|
|
270
|
+
it("should show the dismiss button", async () => {
|
|
264
271
|
const options: testRendererOptions = {
|
|
265
272
|
...getDefaultOptions(),
|
|
266
273
|
fullScreen: true,
|
|
267
274
|
};
|
|
268
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
275
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
269
276
|
expect(
|
|
270
277
|
contentOverlayScreen.getByTestId("ATL-Overlay-CloseButton"),
|
|
271
278
|
).toBeDefined();
|
|
@@ -273,12 +280,12 @@ describe("when fullScreen is set to true", () => {
|
|
|
273
280
|
});
|
|
274
281
|
|
|
275
282
|
describe("when showDismiss is set to true", () => {
|
|
276
|
-
it("should show the dismiss button", () => {
|
|
283
|
+
it("should show the dismiss button", async () => {
|
|
277
284
|
const options: testRendererOptions = {
|
|
278
285
|
...getDefaultOptions(),
|
|
279
286
|
showDismiss: true,
|
|
280
287
|
};
|
|
281
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
288
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
282
289
|
expect(
|
|
283
290
|
contentOverlayScreen.getByTestId("ATL-Overlay-CloseButton"),
|
|
284
291
|
).toBeDefined();
|
|
@@ -292,7 +299,7 @@ describe("when the close button is clicked on an open content overlay with a def
|
|
|
292
299
|
onBeforeExitCallback: jest.fn(),
|
|
293
300
|
showDismiss: true,
|
|
294
301
|
};
|
|
295
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
302
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
296
303
|
|
|
297
304
|
act(() => {
|
|
298
305
|
fireEvent.press(
|
|
@@ -308,11 +315,11 @@ describe("when the close button is clicked on an open content overlay with a def
|
|
|
308
315
|
|
|
309
316
|
describe("modalBackgroundColor prop", () => {
|
|
310
317
|
describe("when using the default surface value", () => {
|
|
311
|
-
it("renders the component with the color-surface color", () => {
|
|
318
|
+
it("renders the component with the color-surface color", async () => {
|
|
312
319
|
const options: testRendererOptions = {
|
|
313
320
|
...getDefaultOptions(),
|
|
314
321
|
};
|
|
315
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
322
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
316
323
|
const OverlayHeader = contentOverlayScreen.getByTestId(
|
|
317
324
|
"ATL-Overlay-Header",
|
|
318
325
|
).children[0] as ReactTestInstance;
|
|
@@ -337,12 +344,12 @@ describe("modalBackgroundColor prop", () => {
|
|
|
337
344
|
});
|
|
338
345
|
|
|
339
346
|
describe("when set to background", () => {
|
|
340
|
-
it("changes the backround color of the modal to color-surface--background", () => {
|
|
347
|
+
it("changes the backround color of the modal to color-surface--background", async () => {
|
|
341
348
|
const options: testRendererOptions = {
|
|
342
349
|
...getDefaultOptions(),
|
|
343
350
|
modalBackgroundColor: "background",
|
|
344
351
|
};
|
|
345
|
-
const contentOverlayScreen = renderAndOpenContentOverlay(options);
|
|
352
|
+
const contentOverlayScreen = await renderAndOpenContentOverlay(options);
|
|
346
353
|
const OverlayHeader = contentOverlayScreen.getByTestId(
|
|
347
354
|
"ATL-Overlay-Header",
|
|
348
355
|
).children[0] as ReactTestInstance;
|
|
@@ -7,7 +7,7 @@ import React, {
|
|
|
7
7
|
useRef,
|
|
8
8
|
useState,
|
|
9
9
|
} from "react";
|
|
10
|
-
import { Modalize } from "react-native-modalize";
|
|
10
|
+
import type { Modalize } from "react-native-modalize";
|
|
11
11
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
12
12
|
import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native";
|
|
13
13
|
import {
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
ContentOverlayRef,
|
|
27
27
|
ModalBackgroundColor,
|
|
28
28
|
} from "./types";
|
|
29
|
+
import { UNSAFE_WrappedModalize } from "./UNSAFE_WrappedModalize";
|
|
29
30
|
import { useIsScreenReaderEnabled } from "../hooks";
|
|
30
31
|
import { IconButton } from "../IconButton";
|
|
31
32
|
import { Heading } from "../Heading";
|
|
@@ -153,7 +154,7 @@ function ContentOverlayInternal(
|
|
|
153
154
|
return (
|
|
154
155
|
<>
|
|
155
156
|
{headerHeightKnown && childrenHeightKnown && (
|
|
156
|
-
<
|
|
157
|
+
<UNSAFE_WrappedModalize
|
|
157
158
|
ref={callbackInternalRef}
|
|
158
159
|
overlayStyle={styles.overlay}
|
|
159
160
|
handleStyle={styles.handle}
|
|
@@ -196,7 +197,7 @@ function ContentOverlayInternal(
|
|
|
196
197
|
>
|
|
197
198
|
{Platform.OS === "android" ? renderedHeader : undefined}
|
|
198
199
|
{renderedChildren}
|
|
199
|
-
</
|
|
200
|
+
</UNSAFE_WrappedModalize>
|
|
200
201
|
)}
|
|
201
202
|
{!childrenHeightKnown && (
|
|
202
203
|
<View style={[styles.hiddenContent, modalStyle]}>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useRef,
|
|
5
|
+
useState,
|
|
6
|
+
} from "react";
|
|
7
|
+
import { Modalize } from "react-native-modalize";
|
|
8
|
+
import type { IHandles } from "react-native-modalize/lib/options";
|
|
9
|
+
|
|
10
|
+
type Props = React.ComponentProps<typeof Modalize>;
|
|
11
|
+
|
|
12
|
+
export const UNSAFE_WrappedModalize = forwardRef<IHandles, Props>(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
const innerRef = useRef<IHandles | null>(null);
|
|
15
|
+
const [openRenderId, setOpenRenderId] = useState(0);
|
|
16
|
+
|
|
17
|
+
useImperativeHandle(
|
|
18
|
+
ref,
|
|
19
|
+
() => ({
|
|
20
|
+
open(dest) {
|
|
21
|
+
setOpenRenderId(id => id + 1);
|
|
22
|
+
// Open on a fresh tick for additional safety
|
|
23
|
+
requestAnimationFrame(() => {
|
|
24
|
+
innerRef.current?.open(dest);
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
close(dest) {
|
|
28
|
+
innerRef.current?.close(dest);
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
[],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Use a unique key to force a remount, ensuring we get fresh gesture handler nodes within modalize
|
|
35
|
+
return (
|
|
36
|
+
<Modalize key={`modalize-${openRenderId}`} ref={innerRef} {...props} />
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
UNSAFE_WrappedModalize.displayName = "UNSAFE_WrappedModalize";
|