@terreno/ui 57.7.0 → 57.8.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/Avatar.js +2 -2
- package/dist/Avatar.js.map +1 -1
- package/dist/Button.js +2 -2
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +49 -0
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeActionSheet.js +2 -2
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.js +3 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DropdownPanel.d.ts.map +1 -1
- package/dist/DropdownPanel.js +1 -1
- package/dist/DropdownPanel.js.map +1 -1
- package/dist/HeightField.js +2 -2
- package/dist/HeightField.js.map +1 -1
- package/dist/IconButton.d.ts.map +1 -1
- package/dist/IconButton.js +9 -6
- package/dist/IconButton.js.map +1 -1
- package/dist/MediaQuery.d.ts +10 -0
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +13 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/MultiselectField.js +2 -2
- package/dist/MultiselectField.js.map +1 -1
- package/dist/RadioField.js +2 -2
- package/dist/RadioField.js.map +1 -1
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +126 -21
- package/dist/SplitPage.js.map +1 -1
- package/dist/UnifiedAddressAutoComplete.js +2 -2
- package/dist/UnifiedAddressAutoComplete.js.map +1 -1
- package/dist/fieldElements/FieldTitle.js +2 -2
- package/dist/fieldElements/FieldTitle.js.map +1 -1
- package/package.json +1 -1
- package/src/Avatar.tsx +2 -2
- package/src/Button.test.tsx +7 -7
- package/src/Button.tsx +2 -2
- package/src/Common.ts +50 -0
- package/src/DateTimeActionSheet.tsx +4 -4
- package/src/DateTimeField.test.tsx +5 -4
- package/src/DateTimeField.tsx +3 -3
- package/src/DropdownPanel.test.tsx +12 -0
- package/src/DropdownPanel.tsx +8 -1
- package/src/HeightField.tsx +2 -2
- package/src/IconButton.test.tsx +63 -0
- package/src/IconButton.tsx +10 -5
- package/src/MediaQuery.ts +14 -1
- package/src/MultiselectField.tsx +2 -2
- package/src/RadioField.tsx +2 -2
- package/src/SplitPage.test.tsx +449 -11
- package/src/SplitPage.tsx +255 -21
- package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
- package/src/UnifiedAddressAutoComplete.tsx +2 -2
- package/src/__snapshots__/DropdownPanel.test.tsx.snap +3 -1
- package/src/bunSetup.ts +2 -1
- package/src/fieldElements/FieldTitle.tsx +2 -2
package/src/SplitPage.tsx
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
type ComponentProps,
|
|
4
|
+
type ElementRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import {
|
|
11
|
+
type LayoutChangeEvent,
|
|
12
|
+
type ListRenderItemInfo,
|
|
13
|
+
ScrollView,
|
|
14
|
+
useWindowDimensions,
|
|
15
|
+
View,
|
|
16
|
+
} from "react-native";
|
|
3
17
|
import {SwiperFlatList} from "react-native-swiper-flatlist";
|
|
4
18
|
|
|
5
19
|
import {Box} from "./Box";
|
|
6
20
|
import type {SplitPageListItem, SplitPageProps} from "./Common";
|
|
7
21
|
import {FlatList} from "./FlatList";
|
|
8
22
|
import {IconButton} from "./IconButton";
|
|
9
|
-
import {
|
|
23
|
+
import {isNarrowViewport} from "./MediaQuery";
|
|
10
24
|
import {SegmentedControl} from "./SegmentedControl";
|
|
11
25
|
import {Spinner} from "./Spinner";
|
|
12
26
|
import {useTheme} from "./Theme";
|
|
13
27
|
|
|
14
28
|
// A component for rendering a list on one side and a details view on the right for large screens,
|
|
15
29
|
// and a scrollable list where clicking an item takes you the details view.
|
|
30
|
+
// On web, opt in to minimum widths for the desktop side-by-side children, or a labeled pager
|
|
31
|
+
// on the narrow viewport. `narrowBelowWidth` chooses that viewport from the window width;
|
|
32
|
+
// otherwise it follows `isNarrowViewport()`. The native SplitPage ignores those props.
|
|
16
33
|
export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
17
34
|
children,
|
|
18
35
|
tabs = [],
|
|
@@ -28,14 +45,28 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
28
45
|
listViewWidth,
|
|
29
46
|
listViewMaxWidth,
|
|
30
47
|
bottomNavBarHeight,
|
|
48
|
+
desktopChildrenMinWidth,
|
|
49
|
+
narrowBelowWidth,
|
|
50
|
+
narrowViewportChildLabels,
|
|
51
|
+
narrowViewportListButtonLabel,
|
|
52
|
+
narrowViewportSelectionActive,
|
|
53
|
+
narrowViewportSelectionKey,
|
|
31
54
|
showItemList,
|
|
32
55
|
}: SplitPageProps<TItem>) => {
|
|
33
56
|
const {theme} = useTheme();
|
|
57
|
+
const {width: windowWidth} = useWindowDimensions();
|
|
34
58
|
const [selectedId, setSelectedId] = useState<number | undefined>(undefined);
|
|
35
59
|
const [activeTabs, setActiveTabs] = useState<number[]>([0, 1]);
|
|
36
|
-
const
|
|
60
|
+
const [activeChildIndex, setActiveChildIndex] = useState(0);
|
|
61
|
+
const activeChildIndexRef = useRef(activeChildIndex);
|
|
62
|
+
activeChildIndexRef.current = activeChildIndex;
|
|
63
|
+
const swiperRef = useRef<ElementRef<typeof SwiperFlatList> | null>(null);
|
|
64
|
+
const [desktopScrollWidth, setDesktopScrollWidth] = useState(0);
|
|
65
|
+
const [measuredPageWidth, setMeasuredPageWidth] = useState(0);
|
|
37
66
|
|
|
38
|
-
const
|
|
67
|
+
const isNarrowLayout =
|
|
68
|
+
narrowBelowWidth === undefined ? isNarrowViewport() : windowWidth <= narrowBelowWidth;
|
|
69
|
+
const isDetailActive = selectedId !== undefined || narrowViewportSelectionActive === true;
|
|
39
70
|
|
|
40
71
|
const elementArray = Children.toArray(children).filter((c) => c !== null);
|
|
41
72
|
|
|
@@ -59,6 +90,23 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
59
90
|
}
|
|
60
91
|
}, [showItemList, onItemDeselect]);
|
|
61
92
|
|
|
93
|
+
// Reset the narrow pager when the selected record changes. Width changes stay out of this effect
|
|
94
|
+
// so a resize does not jump back to the first child.
|
|
95
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: these values are the reset triggers.
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
setActiveChildIndex(0);
|
|
98
|
+
swiperRef.current?.scrollToIndex({animated: false, index: 0});
|
|
99
|
+
}, [isDetailActive, isNarrowLayout, narrowViewportSelectionKey, selectedId]);
|
|
100
|
+
|
|
101
|
+
// Keep the current child aligned after the page width changes, without snapping over a chevron animation.
|
|
102
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: widths are the realign triggers; the index is read from a ref.
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
swiperRef.current?.scrollToIndex({
|
|
105
|
+
animated: false,
|
|
106
|
+
index: activeChildIndexRef.current,
|
|
107
|
+
});
|
|
108
|
+
}, [measuredPageWidth, windowWidth]);
|
|
109
|
+
|
|
62
110
|
if (!children && !renderContent) {
|
|
63
111
|
console.warn("A child node is required");
|
|
64
112
|
return null;
|
|
@@ -69,6 +117,19 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
69
117
|
return null;
|
|
70
118
|
}
|
|
71
119
|
|
|
120
|
+
if (desktopChildrenMinWidth !== undefined && elementArray.length > 2) {
|
|
121
|
+
console.warn("desktopChildrenMinWidth applies only when SplitPage has two or fewer children.");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
narrowViewportChildLabels !== undefined &&
|
|
126
|
+
narrowViewportChildLabels.length !== elementArray.length
|
|
127
|
+
) {
|
|
128
|
+
console.warn(
|
|
129
|
+
"narrowViewportChildLabels must have one entry per child. Falling back to the default narrow pager."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
72
133
|
const renderItem = (itemInfo: ListRenderItemInfo<TItem>) => {
|
|
73
134
|
return (
|
|
74
135
|
<Box
|
|
@@ -163,33 +224,82 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
163
224
|
</Box>
|
|
164
225
|
</View>
|
|
165
226
|
);
|
|
166
|
-
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
desktopChildrenMinWidth !== undefined &&
|
|
231
|
+
elementArray.length >= 1 &&
|
|
232
|
+
elementArray.length <= 2
|
|
233
|
+
) {
|
|
234
|
+
const childCount = elementArray.length;
|
|
235
|
+
const childWidth =
|
|
236
|
+
desktopScrollWidth > 0
|
|
237
|
+
? Math.max(desktopChildrenMinWidth, desktopScrollWidth / childCount)
|
|
238
|
+
: desktopChildrenMinWidth;
|
|
239
|
+
const rowWidth = Math.max(
|
|
240
|
+
desktopScrollWidth,
|
|
241
|
+
desktopChildrenMinWidth * childCount,
|
|
242
|
+
childWidth * childCount
|
|
243
|
+
);
|
|
167
244
|
return (
|
|
168
|
-
<
|
|
245
|
+
<ScrollView
|
|
246
|
+
contentContainerStyle={{flexDirection: "row", width: rowWidth}}
|
|
247
|
+
horizontal
|
|
248
|
+
nestedScrollEnabled
|
|
249
|
+
onLayout={(event: LayoutChangeEvent) => {
|
|
250
|
+
const nextWidth = event.nativeEvent.layout.width;
|
|
251
|
+
setDesktopScrollWidth((current) => (current === nextWidth ? current : nextWidth));
|
|
252
|
+
}}
|
|
253
|
+
style={{flex: 1, height: "100%"}}
|
|
254
|
+
testID="split-page-desktop-children-scroll"
|
|
255
|
+
>
|
|
169
256
|
{elementArray.map((element, index) => {
|
|
170
257
|
return (
|
|
171
258
|
<ScrollView
|
|
172
|
-
contentContainerStyle={{
|
|
173
|
-
flex: 1,
|
|
174
|
-
}}
|
|
259
|
+
contentContainerStyle={{flexGrow: 1}}
|
|
175
260
|
key={index}
|
|
176
261
|
style={{
|
|
177
|
-
|
|
262
|
+
flexGrow: 0,
|
|
263
|
+
flexShrink: 0,
|
|
178
264
|
height: "100%",
|
|
179
|
-
|
|
265
|
+
maxWidth: childWidth,
|
|
266
|
+
width: childWidth,
|
|
180
267
|
}}
|
|
268
|
+
testID={`split-page-desktop-child-${index}`}
|
|
181
269
|
>
|
|
182
270
|
{element}
|
|
183
271
|
</ScrollView>
|
|
184
272
|
);
|
|
185
273
|
})}
|
|
186
|
-
</
|
|
274
|
+
</ScrollView>
|
|
187
275
|
);
|
|
188
276
|
}
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<Box alignItems="center" direction="row" flex="grow" justifyContent="center" paddingX={2}>
|
|
280
|
+
{elementArray.map((element, index) => {
|
|
281
|
+
return (
|
|
282
|
+
<ScrollView
|
|
283
|
+
contentContainerStyle={{
|
|
284
|
+
flex: 1,
|
|
285
|
+
}}
|
|
286
|
+
key={index}
|
|
287
|
+
style={{
|
|
288
|
+
flex: 1,
|
|
289
|
+
height: "100%",
|
|
290
|
+
width: "60%",
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
{element}
|
|
294
|
+
</ScrollView>
|
|
295
|
+
);
|
|
296
|
+
})}
|
|
297
|
+
</Box>
|
|
298
|
+
);
|
|
189
299
|
};
|
|
190
300
|
|
|
191
301
|
const renderMobileList = () => {
|
|
192
|
-
if (
|
|
302
|
+
if (isNarrowLayout && isDetailActive) {
|
|
193
303
|
return null;
|
|
194
304
|
}
|
|
195
305
|
|
|
@@ -218,13 +328,13 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
218
328
|
};
|
|
219
329
|
|
|
220
330
|
const renderMobileListContent = () => {
|
|
221
|
-
if (
|
|
331
|
+
if (isNarrowLayout && !isDetailActive) {
|
|
222
332
|
return null;
|
|
223
333
|
}
|
|
224
334
|
|
|
225
335
|
return (
|
|
226
336
|
<Box flex="grow" padding={2}>
|
|
227
|
-
{
|
|
337
|
+
{isNarrowLayout && (
|
|
228
338
|
<Box width="100%">
|
|
229
339
|
<IconButton
|
|
230
340
|
accessibilityHint="close split page"
|
|
@@ -239,10 +349,126 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
239
349
|
);
|
|
240
350
|
};
|
|
241
351
|
|
|
352
|
+
const showMobileChild = (destination: number): void => {
|
|
353
|
+
setActiveChildIndex(destination);
|
|
354
|
+
swiperRef.current?.scrollToIndex({animated: true, index: destination});
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
const renderLabeledMobilePager = (labels: string[]) => {
|
|
358
|
+
const pageWidth = measuredPageWidth > 0 ? measuredPageWidth : windowWidth;
|
|
359
|
+
const lastIndex = elementArray.length - 1;
|
|
360
|
+
const controlBottom = (bottomNavBarHeight ?? 0) + 8;
|
|
361
|
+
return (
|
|
362
|
+
<View
|
|
363
|
+
onLayout={(event: LayoutChangeEvent) => {
|
|
364
|
+
const nextWidth = event.nativeEvent.layout.width;
|
|
365
|
+
setMeasuredPageWidth((current) => (current === nextWidth ? current : nextWidth));
|
|
366
|
+
}}
|
|
367
|
+
style={{flex: 1, width: "100%"}}
|
|
368
|
+
testID="split-page-mobile-children"
|
|
369
|
+
>
|
|
370
|
+
<SwiperFlatList
|
|
371
|
+
getItemLayout={(_data, index) => ({
|
|
372
|
+
index,
|
|
373
|
+
length: pageWidth,
|
|
374
|
+
offset: pageWidth * index,
|
|
375
|
+
})}
|
|
376
|
+
nestedScrollEnabled
|
|
377
|
+
onChangeIndex={({index}) => {
|
|
378
|
+
setActiveChildIndex(index);
|
|
379
|
+
}}
|
|
380
|
+
ref={swiperRef}
|
|
381
|
+
renderAll
|
|
382
|
+
style={{width: "100%"}}
|
|
383
|
+
>
|
|
384
|
+
{elementArray.map((element, index) => {
|
|
385
|
+
return (
|
|
386
|
+
<View
|
|
387
|
+
key={index}
|
|
388
|
+
style={{
|
|
389
|
+
height: "100%",
|
|
390
|
+
padding: 0,
|
|
391
|
+
paddingBottom: bottomNavBarHeight,
|
|
392
|
+
width: pageWidth,
|
|
393
|
+
}}
|
|
394
|
+
testID={`split-page-mobile-child-${index}`}
|
|
395
|
+
>
|
|
396
|
+
{element}
|
|
397
|
+
</View>
|
|
398
|
+
);
|
|
399
|
+
})}
|
|
400
|
+
</SwiperFlatList>
|
|
401
|
+
{narrowViewportListButtonLabel ? (
|
|
402
|
+
<View
|
|
403
|
+
style={{
|
|
404
|
+
bottom: controlBottom,
|
|
405
|
+
left: 16,
|
|
406
|
+
position: "absolute",
|
|
407
|
+
zIndex: 1,
|
|
408
|
+
}}
|
|
409
|
+
>
|
|
410
|
+
<IconButton
|
|
411
|
+
accessibilityHint={narrowViewportListButtonLabel}
|
|
412
|
+
accessibilityLabel={narrowViewportListButtonLabel}
|
|
413
|
+
backgroundOpacity={0.88}
|
|
414
|
+
iconName="arrow-left"
|
|
415
|
+
onClick={() => onItemDeselect()}
|
|
416
|
+
testID="split-page-back-to-list"
|
|
417
|
+
variant="muted"
|
|
418
|
+
/>
|
|
419
|
+
</View>
|
|
420
|
+
) : null}
|
|
421
|
+
<View
|
|
422
|
+
style={{
|
|
423
|
+
bottom: controlBottom,
|
|
424
|
+
flexDirection: "row",
|
|
425
|
+
gap: 8,
|
|
426
|
+
position: "absolute",
|
|
427
|
+
right: 16,
|
|
428
|
+
zIndex: 1,
|
|
429
|
+
}}
|
|
430
|
+
>
|
|
431
|
+
{activeChildIndex > 0 ? (
|
|
432
|
+
<IconButton
|
|
433
|
+
accessibilityLabel={`Show previous column: ${labels[activeChildIndex - 1]}`}
|
|
434
|
+
backgroundOpacity={0.88}
|
|
435
|
+
iconName="chevron-left"
|
|
436
|
+
onClick={() => {
|
|
437
|
+
showMobileChild(activeChildIndex - 1);
|
|
438
|
+
}}
|
|
439
|
+
testID="split-page-column-previous"
|
|
440
|
+
variant="muted"
|
|
441
|
+
/>
|
|
442
|
+
) : null}
|
|
443
|
+
{activeChildIndex < lastIndex ? (
|
|
444
|
+
<IconButton
|
|
445
|
+
accessibilityLabel={`Show next column: ${labels[activeChildIndex + 1]}`}
|
|
446
|
+
backgroundOpacity={0.88}
|
|
447
|
+
iconName="chevron-right"
|
|
448
|
+
onClick={() => {
|
|
449
|
+
showMobileChild(activeChildIndex + 1);
|
|
450
|
+
}}
|
|
451
|
+
testID="split-page-column-next"
|
|
452
|
+
variant="muted"
|
|
453
|
+
/>
|
|
454
|
+
) : null}
|
|
455
|
+
</View>
|
|
456
|
+
</View>
|
|
457
|
+
);
|
|
458
|
+
};
|
|
459
|
+
|
|
242
460
|
const renderMobileChildrenContent = () => {
|
|
243
|
-
if (
|
|
461
|
+
if (!isDetailActive) {
|
|
244
462
|
return null;
|
|
245
463
|
}
|
|
464
|
+
if (
|
|
465
|
+
isNarrowLayout &&
|
|
466
|
+
elementArray.length > 1 &&
|
|
467
|
+
narrowViewportChildLabels !== undefined &&
|
|
468
|
+
narrowViewportChildLabels.length === elementArray.length
|
|
469
|
+
) {
|
|
470
|
+
return renderLabeledMobilePager(narrowViewportChildLabels);
|
|
471
|
+
}
|
|
246
472
|
return (
|
|
247
473
|
<SwiperFlatList
|
|
248
474
|
nestedScrollEnabled
|
|
@@ -259,7 +485,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
259
485
|
height: elementArray.length > 1 ? "90%" : "100%",
|
|
260
486
|
padding: 4,
|
|
261
487
|
paddingBottom: bottomNavBarHeight,
|
|
262
|
-
width:
|
|
488
|
+
width: windowWidth - 8,
|
|
263
489
|
}}
|
|
264
490
|
>
|
|
265
491
|
{element}
|
|
@@ -283,9 +509,17 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
283
509
|
const renderMainContent = renderContent
|
|
284
510
|
? renderMobileListContent()
|
|
285
511
|
: renderMobileChildrenContent();
|
|
286
|
-
return
|
|
512
|
+
return isDetailActive ? renderMainContent : renderMobileList();
|
|
287
513
|
};
|
|
288
514
|
|
|
515
|
+
const isLabeledPagerBody =
|
|
516
|
+
isNarrowLayout &&
|
|
517
|
+
isDetailActive &&
|
|
518
|
+
!renderContent &&
|
|
519
|
+
elementArray.length > 1 &&
|
|
520
|
+
narrowViewportChildLabels !== undefined &&
|
|
521
|
+
narrowViewportChildLabels.length === elementArray.length;
|
|
522
|
+
|
|
289
523
|
return (
|
|
290
524
|
<Box
|
|
291
525
|
avoidKeyboard
|
|
@@ -294,7 +528,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
294
528
|
display="flex"
|
|
295
529
|
height="100%"
|
|
296
530
|
keyboardOffset={keyboardOffset}
|
|
297
|
-
padding={2}
|
|
531
|
+
padding={isLabeledPagerBody ? 0 : 2}
|
|
298
532
|
width="100%"
|
|
299
533
|
>
|
|
300
534
|
{loading === true && (
|
|
@@ -303,7 +537,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
|
303
537
|
size="md"
|
|
304
538
|
/>
|
|
305
539
|
)}
|
|
306
|
-
{
|
|
540
|
+
{isNarrowLayout ? renderMobileSplitPage() : renderSplitPage()}
|
|
307
541
|
</Box>
|
|
308
542
|
);
|
|
309
543
|
};
|
|
@@ -3,7 +3,7 @@ import {fireEvent} from "@testing-library/react-native";
|
|
|
3
3
|
import {forwardRef} from "react";
|
|
4
4
|
import {Text, View} from "react-native";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {isNarrowViewport} from "./MediaQuery";
|
|
7
7
|
import {renderWithTheme} from "./test-utils";
|
|
8
8
|
import {UnifiedAddressAutoCompleteField} from "./UnifiedAddressAutoComplete";
|
|
9
9
|
|
|
@@ -136,11 +136,11 @@ describe("UnifiedAddressAutoCompleteField", () => {
|
|
|
136
136
|
|
|
137
137
|
describe("mobile/native branch", () => {
|
|
138
138
|
afterEach(() => {
|
|
139
|
-
(
|
|
139
|
+
(isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => false);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
it("renders MobileAddressAutocomplete when
|
|
143
|
-
(
|
|
142
|
+
it("renders MobileAddressAutocomplete when isNarrowViewport + isNative + valid key", () => {
|
|
143
|
+
(isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => true);
|
|
144
144
|
const {getByTestId} = renderWithTheme(
|
|
145
145
|
<UnifiedAddressAutoCompleteField
|
|
146
146
|
{...defaultProps}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useMemo} from "react";
|
|
2
2
|
|
|
3
3
|
import type {AddressAutocompleteProps} from "./Common";
|
|
4
|
-
import {
|
|
4
|
+
import {isNarrowViewport} from "./MediaQuery";
|
|
5
5
|
import {MobileAddressAutocomplete} from "./MobileAddressAutoComplete";
|
|
6
6
|
import {TextField} from "./TextField";
|
|
7
7
|
import {isNative, isValidGoogleApiKey} from "./Utilities";
|
|
@@ -35,7 +35,7 @@ export const UnifiedAddressAutoCompleteField = ({
|
|
|
35
35
|
testID={testID}
|
|
36
36
|
/>
|
|
37
37
|
);
|
|
38
|
-
} else if (
|
|
38
|
+
} else if (isNarrowViewport() && isNative() && isValidatedGoogleApiKey) {
|
|
39
39
|
return (
|
|
40
40
|
<MobileAddressAutocomplete
|
|
41
41
|
disabled={disabled}
|
package/src/bunSetup.ts
CHANGED
|
@@ -850,8 +850,9 @@ mock.module("react-native-actions-sheet", () => ({
|
|
|
850
850
|
|
|
851
851
|
// Mock MediaQuery
|
|
852
852
|
mock.module("./MediaQuery", () => ({
|
|
853
|
-
|
|
853
|
+
isNarrowViewport: mock(() => false),
|
|
854
854
|
mediaQueryLargerThan: mock(() => false),
|
|
855
|
+
mediaQuerySmallerThan: mock(() => false),
|
|
855
856
|
}));
|
|
856
857
|
|
|
857
858
|
// Mock expo-image-manipulator
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type {FC} from "react";
|
|
5
5
|
import {Text} from "react-native";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {isNarrowViewport} from "../MediaQuery";
|
|
8
8
|
import {useTheme} from "../Theme";
|
|
9
9
|
import {toTestProps} from "../testing/resolveTestId";
|
|
10
10
|
import {isNative} from "../Utilities";
|
|
@@ -16,7 +16,7 @@ interface FieldTitleProps {
|
|
|
16
16
|
|
|
17
17
|
export const FieldTitle: FC<FieldTitleProps> = ({text, testID}) => {
|
|
18
18
|
const {theme} = useTheme();
|
|
19
|
-
const isMobileOrNative =
|
|
19
|
+
const isMobileOrNative = isNarrowViewport() || isNative();
|
|
20
20
|
|
|
21
21
|
return (
|
|
22
22
|
<Text
|