From 8a3d13871a40e08e0c3deb302b60bbb2bcffd9f3 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sat, 14 May 2022 12:43:18 +0100 Subject: [PATCH] feat: added data to present modal api (#942) * feat: added data api for modal present * fix: updated rendering children approach --- src/components/bottomSheet/BottomSheet.tsx | 6 ++--- .../bottomSheetModal/BottomSheetModal.tsx | 27 ++++++++++++++----- src/components/bottomSheetModal/types.d.ts | 10 +++++++ src/types.d.ts | 3 ++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index e21a3ca36..1256ba3dd 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -153,7 +153,7 @@ const BottomSheetComponent = forwardRef( backdropComponent, backgroundComponent, footerComponent, - children, + children: Content, } = props; //#endregion @@ -1621,9 +1621,7 @@ const BottomSheetComponent = forwardRef( key="BottomSheetRootDraggableView" style={contentContainerStyle} > - {typeof children === 'function' - ? (children as Function)() - : children} + {typeof Content === 'function' ? : Content} {footerComponent && ( { - setMount(true); + setState({ + mount: true, + data: _data, + }); mountSheet(key, ref, stackBehavior); print({ @@ -348,7 +359,7 @@ const BottomSheetModalComponent = forwardRef< //#endregion // render - // console.log('BottomSheetModal', index, snapPoints) + // console.log('BottomSheetModal', index, mount, data); return mount ? ( : Content + } $modal={true} /> diff --git a/src/components/bottomSheetModal/types.d.ts b/src/components/bottomSheetModal/types.d.ts index 1d6b8271e..e05e451d1 100644 --- a/src/components/bottomSheetModal/types.d.ts +++ b/src/components/bottomSheetModal/types.d.ts @@ -1,3 +1,4 @@ +import type React from 'react'; import type { BottomSheetProps } from '../bottomSheet'; import type { MODAL_STACK_BEHAVIOR } from '../../constants'; @@ -43,4 +44,13 @@ export interface BottomSheetModalProps * @type () => void; */ onDismiss?: () => void; + + /** + * A scrollable node or normal view. + * @type React.ReactNode[] | React.ReactNode + */ + children: + | (({ data: any }?) => React.ReactNode) + | React.ReactNode[] + | React.ReactNode; } diff --git a/src/types.d.ts b/src/types.d.ts index 1b44f1202..2a792c5b2 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -78,8 +78,9 @@ export interface BottomSheetMethods { export interface BottomSheetModalMethods extends BottomSheetMethods { /** * Mount and present the bottom sheet modal to the initial snap point. + * @param data to be passed to the modal. */ - present: () => void; + present: (data?: any) => void; /** * Close and unmount the bottom sheet modal. * @param animationConfigs snap animation configs.