react-native-boxes 1.4.30 → 1.4.32

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Modal.tsx +22 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-boxes",
3
- "version": "1.4.30",
3
+ "version": "1.4.32",
4
4
  "description": "A react native library for rapid development of UI using boxes",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/Modal.tsx CHANGED
@@ -364,22 +364,22 @@ 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
373
  export type DropDownViewProps = {
374
+ listType?: 'sheet' | 'horizontal-list'
374
375
  options: DropDownViewOption[]
375
376
  selectedId: string,
376
377
  onSelect: (selectedId: string, opt: DropDownViewOption) => void
377
378
 
378
379
  initialVisile?: Boolean,
379
380
  title?: string,
380
- listType?: 'sheet' | 'horizontal-list'
381
381
  displayType?: 'button' | 'input',
382
- onRenderOption?: (opt: DropDownViewOption) => any,
382
+ onRenderOption?: (opt: DropDownViewOption, setSelected?: (selectedId: string, opt: DropDownViewOption) => void) => any,
383
383
  forceDialogSelectOnWeb?: Boolean
384
384
  swipeToCloseDisabled?: boolean
385
385
  } & CompositeTextInputViewProps
@@ -393,11 +393,16 @@ export const DropDownView = (props: DropDownViewProps) => {
393
393
  const displayType = props.displayType || 'input'
394
394
  const theme = useContext(ThemeContext)
395
395
  const [visible, setVisible] = useState(props.initialVisile || false)
396
+ const flatlistRef = useRef<FlatList<any>>()
396
397
 
397
398
  const getSelected = (): DropDownViewOption | undefined => {
398
399
  let se = props.options.find(op => op.id == props.selectedId)
399
400
  return se
400
401
  };
402
+ const onSelect = (selectedId: string, opt: DropDownViewOption) => {
403
+ props.onSelect(selectedId, opt)
404
+ setVisible(false)
405
+ }
401
406
  const shouldShowLabel = props.listType == 'horizontal-list' ? !visible : true
402
407
  if (Platform.OS == 'web' && !props.forceDialogSelectOnWeb) {
403
408
  return (
@@ -416,7 +421,7 @@ export const DropDownView = (props: DropDownViewProps) => {
416
421
  {
417
422
  props.options.map(opt => {
418
423
  if (props.onRenderOption) {
419
- return props.onRenderOption(opt)
424
+ return props.onRenderOption(opt, onSelect)
420
425
  }
421
426
  return (
422
427
  <option
@@ -437,6 +442,12 @@ export const DropDownView = (props: DropDownViewProps) => {
437
442
  {
438
443
  (visible && props.listType == 'horizontal-list') ? (
439
444
  <FlatList
445
+ style={[{
446
+ marginTop: theme.dimens.space.sm,
447
+ marginBottom: theme.dimens.space.sm,
448
+ }, props.style]}
449
+ //@ts-ignore
450
+ ref={flatlistRef}
440
451
  ItemSeparatorComponent={() => {
441
452
  return (
442
453
  <View
@@ -454,18 +465,20 @@ export const DropDownView = (props: DropDownViewProps) => {
454
465
  renderItem={(item) => {
455
466
  const opt = item.item
456
467
  if (props.onRenderOption) {
457
- return props.onRenderOption(opt)
468
+ return props.onRenderOption(opt, onSelect)
458
469
  }
459
470
  return (
460
471
  <PressableView
461
472
  onPress={() => {
473
+ setVisible(false)
462
474
  props.onSelect(opt.id, opt)
463
475
  }}>
464
476
  <Center style={{
477
+ borderWidth: 1,
465
478
  borderRadius: theme.dimens.space.md,
466
- width: theme.dimens.space.xl * 1.5,
467
- height: theme.dimens.space.xl * 1.5,
468
- backgroundColor: props.selectedId == opt?.id ?
479
+ width: theme.dimens.space.xl * 1.4,
480
+ height: theme.dimens.space.xl * 1.4,
481
+ borderColor: props.selectedId == opt?.id ?
469
482
  theme.colors.accent : theme.colors.background,
470
483
  padding: theme.dimens.space.md
471
484
  }}>
@@ -493,7 +506,7 @@ export const DropDownView = (props: DropDownViewProps) => {
493
506
  {
494
507
  props.options.map((opt, idx) => {
495
508
  if (props.onRenderOption) {
496
- return props.onRenderOption(opt)
509
+ return props.onRenderOption(opt, onSelect)
497
510
  }
498
511
  return (
499
512
  <TertiaryButtonView
@@ -563,7 +576,6 @@ export const DropDownView = (props: DropDownViewProps) => {
563
576
  }
564
577
 
565
578
 
566
-
567
579
  export type ConfirmationDialogProps = {
568
580
  visible: boolean,
569
581
  title?: string | React.Component,