react-native-boxes 1.4.29 → 1.4.31
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/package.json +1 -1
- package/src/Modal.tsx +130 -63
package/package.json
CHANGED
package/src/Modal.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { Animated, Button, Easing, LayoutChangeEvent, Linking, Modal, Platform, Pressable, ScrollView, StyleProp, StyleSheet, TextStyle, TouchableHighlight, TouchableOpacity, View, ViewProps, ViewStyle } from 'react-native';
|
|
3
|
+
import { Animated, Button, Easing, FlatList, LayoutChangeEvent, Linking, Modal, Platform, Pressable, ScrollView, StyleProp, StyleSheet, TextStyle, TouchableHighlight, TouchableOpacity, View, ViewProps, ViewStyle } from 'react-native';
|
|
4
4
|
import { getIcon, Icon, IconProps } from './Image';
|
|
5
5
|
import { getNavParamsFromDeeplink, isDesktop, isWeb } from './utils';
|
|
6
6
|
import { ThemeContext } from './ThemeContext';
|
|
7
7
|
import { Center, HBox, VBox, VPage } from './Box';
|
|
8
|
-
import { Subtitle, TextView, Title } from './Text';
|
|
8
|
+
import { Caption, Subtitle, TextView, Title } from './Text';
|
|
9
9
|
import { ButtonView, ButtonViewProps, LoadingButton, PressableView, TertiaryButtonView } from './Button';
|
|
10
10
|
import { CompositeTextInputView, CompositeTextInputViewProps } from './Input';
|
|
11
11
|
import * as WebBrowser from 'expo-web-browser';
|
|
@@ -364,12 +364,14 @@ export function Expand(props: ViewProps & {
|
|
|
364
364
|
);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
|
|
367
368
|
export type DropDownViewOption = {
|
|
368
369
|
id: string
|
|
369
370
|
value: any
|
|
370
371
|
title?: string
|
|
371
372
|
}
|
|
372
373
|
export type DropDownViewProps = {
|
|
374
|
+
listType?: 'sheet' | 'horizontal-list'
|
|
373
375
|
options: DropDownViewOption[]
|
|
374
376
|
selectedId: string,
|
|
375
377
|
onSelect: (selectedId: string, opt: DropDownViewOption) => void
|
|
@@ -391,12 +393,13 @@ export const DropDownView = (props: DropDownViewProps) => {
|
|
|
391
393
|
const displayType = props.displayType || 'input'
|
|
392
394
|
const theme = useContext(ThemeContext)
|
|
393
395
|
const [visible, setVisible] = useState(props.initialVisile || false)
|
|
396
|
+
const flatlistRef = useRef<FlatList<any>>()
|
|
394
397
|
|
|
395
398
|
const getSelected = (): DropDownViewOption | undefined => {
|
|
396
399
|
let se = props.options.find(op => op.id == props.selectedId)
|
|
397
400
|
return se
|
|
398
401
|
};
|
|
399
|
-
|
|
402
|
+
const shouldShowLabel = props.listType == 'horizontal-list' ? !visible : true
|
|
400
403
|
if (Platform.OS == 'web' && !props.forceDialogSelectOnWeb) {
|
|
401
404
|
return (
|
|
402
405
|
<select
|
|
@@ -428,78 +431,140 @@ export const DropDownView = (props: DropDownViewProps) => {
|
|
|
428
431
|
</select>
|
|
429
432
|
)
|
|
430
433
|
}
|
|
431
|
-
|
|
432
434
|
else {
|
|
433
435
|
return (
|
|
434
436
|
<VBox style={props.style}>
|
|
435
|
-
<BottomSheet
|
|
436
|
-
swipeToCloseDisabled={props.swipeToCloseDisabled}
|
|
437
|
-
visible={visible as boolean}
|
|
438
|
-
onDismiss={() => {
|
|
439
|
-
setVisible(false)
|
|
440
|
-
}}
|
|
441
|
-
title={props.title || ''} >
|
|
442
|
-
{
|
|
443
|
-
props.options.map((opt, idx) => {
|
|
444
|
-
if (props.onRenderOption) {
|
|
445
|
-
return props.onRenderOption(opt)
|
|
446
|
-
}
|
|
447
|
-
return (
|
|
448
|
-
<TertiaryButtonView
|
|
449
|
-
onPress={() => {
|
|
450
|
-
setVisible(false)
|
|
451
|
-
props.onSelect(opt.id, opt)
|
|
452
|
-
}}
|
|
453
|
-
style={{
|
|
454
|
-
padding: 0,
|
|
455
|
-
paddingBottom: idx == props.options.length - 1 ? theme.dimens.space.md : 0,
|
|
456
|
-
paddingTop: idx == 0 ? theme.dimens.space.md : 0,
|
|
457
|
-
}}
|
|
458
|
-
key={opt.id} >{opt.title || opt.value}</TertiaryButtonView>
|
|
459
|
-
)
|
|
460
|
-
})
|
|
461
|
-
}
|
|
462
|
-
</BottomSheet>
|
|
463
437
|
|
|
464
438
|
{
|
|
465
|
-
|
|
439
|
+
(visible && props.listType == 'horizontal-list') ? (
|
|
440
|
+
<FlatList
|
|
441
|
+
style={[{
|
|
442
|
+
marginTop: theme.dimens.space.sm,
|
|
443
|
+
marginBottom: theme.dimens.space.sm,
|
|
444
|
+
}, props.style]}
|
|
445
|
+
//@ts-ignore
|
|
446
|
+
ref={flatlistRef}
|
|
447
|
+
ItemSeparatorComponent={() => {
|
|
448
|
+
return (
|
|
449
|
+
<View
|
|
450
|
+
style={{
|
|
451
|
+
height: "100%",
|
|
452
|
+
width: theme.dimens.space.sm,
|
|
453
|
+
backgroundColor: theme.colors.forground,
|
|
466
454
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
onPress={() => {
|
|
471
|
-
setVisible(true)
|
|
455
|
+
}}
|
|
456
|
+
/>
|
|
457
|
+
);
|
|
472
458
|
}}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
459
|
+
horizontal={true}
|
|
460
|
+
data={props.options}
|
|
461
|
+
renderItem={(item) => {
|
|
462
|
+
const opt = item.item
|
|
463
|
+
if (props.onRenderOption) {
|
|
464
|
+
return props.onRenderOption(opt)
|
|
465
|
+
}
|
|
466
|
+
return (
|
|
467
|
+
<PressableView
|
|
468
|
+
onPress={() => {
|
|
469
|
+
setVisible(false)
|
|
470
|
+
props.onSelect(opt.id, opt)
|
|
471
|
+
}}>
|
|
472
|
+
<Center style={{
|
|
473
|
+
borderWidth: 1,
|
|
474
|
+
borderRadius: theme.dimens.space.md,
|
|
475
|
+
width: theme.dimens.space.xl * 1.4,
|
|
476
|
+
height: theme.dimens.space.xl * 1.4,
|
|
477
|
+
borderColor: props.selectedId == opt?.id ?
|
|
478
|
+
theme.colors.accent : theme.colors.background,
|
|
479
|
+
padding: theme.dimens.space.md
|
|
480
|
+
}}>
|
|
481
|
+
<Caption style={{
|
|
482
|
+
color: theme.colors.text,
|
|
483
|
+
}}>{opt?.title || opt.id}</Caption>
|
|
484
|
+
|
|
485
|
+
</Center>
|
|
486
|
+
</PressableView>
|
|
487
|
+
)
|
|
481
488
|
}}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
489
|
+
keyExtractor={(item) => item?.id || `${Date.now()}`}
|
|
490
|
+
extraData={props.selectedId}
|
|
491
|
+
/>
|
|
492
|
+
) :
|
|
493
|
+
|
|
494
|
+
(
|
|
495
|
+
<BottomSheet
|
|
496
|
+
swipeToCloseDisabled={props.swipeToCloseDisabled}
|
|
497
|
+
visible={visible as boolean}
|
|
498
|
+
onDismiss={() => {
|
|
499
|
+
setVisible(false)
|
|
500
|
+
}}
|
|
501
|
+
title={props.title || ''} >
|
|
502
|
+
{
|
|
503
|
+
props.options.map((opt, idx) => {
|
|
504
|
+
if (props.onRenderOption) {
|
|
505
|
+
return props.onRenderOption(opt)
|
|
506
|
+
}
|
|
507
|
+
return (
|
|
508
|
+
<TertiaryButtonView
|
|
509
|
+
onPress={() => {
|
|
510
|
+
setVisible(false)
|
|
511
|
+
props.onSelect(opt.id, opt)
|
|
512
|
+
}}
|
|
513
|
+
style={{
|
|
514
|
+
padding: 0,
|
|
515
|
+
paddingBottom: idx == props.options.length - 1 ? theme.dimens.space.md : 0,
|
|
516
|
+
paddingTop: idx == 0 ? theme.dimens.space.md : 0,
|
|
517
|
+
}}
|
|
518
|
+
key={opt.id} >{opt.title || opt.value}</TertiaryButtonView>
|
|
519
|
+
)
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
</BottomSheet>
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
{
|
|
527
|
+
shouldShowLabel && (
|
|
528
|
+
displayType == 'button' ? (
|
|
529
|
+
|
|
530
|
+
//@ts-ignore
|
|
531
|
+
<ButtonView
|
|
486
532
|
{...props}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
icon={"caret-down"}
|
|
490
|
-
pointerEvents="none"
|
|
491
|
-
//@ts-ignore
|
|
492
|
-
_textInputProps={{
|
|
493
|
-
caretHidden: true,
|
|
494
|
-
placeholder: props.title || 'select',
|
|
495
|
-
editable: false,
|
|
496
|
-
selectTextOnFocus: false
|
|
533
|
+
onPress={() => {
|
|
534
|
+
setVisible(true)
|
|
497
535
|
}}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
536
|
+
text={getSelected()?.title || getSelected()?.id || 'select'} style={props.style}>
|
|
537
|
+
</ButtonView>
|
|
538
|
+
) : (
|
|
539
|
+
//@ts-ignore
|
|
540
|
+
<PressableView
|
|
541
|
+
{...props}
|
|
542
|
+
onPress={() => {
|
|
543
|
+
setVisible(true)
|
|
544
|
+
}}
|
|
545
|
+
>
|
|
546
|
+
<CompositeTextInputView
|
|
547
|
+
readOnly={true}
|
|
548
|
+
placeholder={props.title}
|
|
549
|
+
{...props}
|
|
550
|
+
value={getSelected()?.title || getSelected()?.id || props.title}
|
|
551
|
+
onIconPress={() => { setVisible(true) }}
|
|
552
|
+
icon={"caret-down"}
|
|
553
|
+
pointerEvents="none"
|
|
554
|
+
//@ts-ignore
|
|
555
|
+
_textInputProps={{
|
|
556
|
+
caretHidden: true,
|
|
557
|
+
placeholder: props.title || 'select',
|
|
558
|
+
editable: false,
|
|
559
|
+
selectTextOnFocus: false
|
|
560
|
+
}}
|
|
561
|
+
hint={props.title || 'select'}
|
|
562
|
+
initialText={getSelected()?.title || getSelected()?.id} />
|
|
563
|
+
</PressableView>
|
|
564
|
+
)
|
|
501
565
|
)
|
|
502
566
|
}
|
|
567
|
+
|
|
503
568
|
</VBox>
|
|
504
569
|
|
|
505
570
|
)
|
|
@@ -507,6 +572,8 @@ export const DropDownView = (props: DropDownViewProps) => {
|
|
|
507
572
|
}
|
|
508
573
|
|
|
509
574
|
|
|
575
|
+
|
|
576
|
+
|
|
510
577
|
export type ConfirmationDialogProps = {
|
|
511
578
|
visible: boolean,
|
|
512
579
|
title?: string | React.Component,
|