Skip to content

Commit 26dfa2b

Browse files
authored
feat: scrollable draggable modal (#116)
1 parent f85b0c0 commit 26dfa2b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

apps/docs/pages/docs/Components/draggable-modal.en-US.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import PropsTable from "@components/docs/props-table";
77

88
# DraggableModal
99

10-
Component to render a draggable modal, based on `react-native-bottom-sheet`
11-
12-
https://github.com/gorhom/react-native-bottom-sheet
10+
Component to render a draggable modal, based on [`react-native-bottom-sheet`](https://github.com/gorhom/react-native-bottom-sheet).
11+
It wraps a `BottomSheetModal` and automatically embeds a `BottomSheetScrollView` so that your content is scrollable out of the box.
1312

1413
## Import
1514

@@ -60,6 +59,7 @@ render(<TestModal />)`} noInline />
6059

6160
Extends every `Box` props and `BottomSheetModalProps` from `@gorhom/bottom-sheet`
6261

62+
6363
### `isOpen`
6464
<PropsTable
6565
description="Boolean to indicate if the modal is opened or not."
@@ -71,3 +71,10 @@ Extends every `Box` props and `BottomSheetModalProps` from `@gorhom/bottom-sheet
7171
description="Method called when the modal is closed by the user."
7272
prop={{ type: "() => void", required: false }}
7373
/>
74+
75+
### `scrollViewProps`
76+
77+
<PropsTable
78+
description="Props forwarded to the internal BottomSheetScrollView (e.g. contentContainerStyle, keyboardShouldPersistTaps, showsVerticalScrollIndicator, ...)."
79+
prop={{ type: "BottomSheetScrollViewProps", required: false }}
80+
/>

packages/react-native-ficus-ui/src/components/draggable-modal/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactNode, useEffect, useRef } from 'react';
22

3-
import { BottomSheetModal } from '@gorhom/bottom-sheet';
3+
import { BottomSheetModal, BottomSheetScrollView } from '@gorhom/bottom-sheet';
4+
import { BottomSheetScrollViewProps } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetScrollable/types';
45
import { SafeAreaView, ViewStyle } from 'react-native';
56

67
import { useColorMode } from '../../hooks';
@@ -17,6 +18,7 @@ import { mergeRefs } from '../utils/merge-refs';
1718
interface DraggableModalOptions {
1819
isOpen?: boolean;
1920
onClose?: () => void;
21+
scrollViewProps?: BottomSheetScrollViewProps;
2022
}
2123

2224
export interface DraggableModalProps
@@ -33,7 +35,7 @@ export const DraggableModal = forwardRef<
3335
const { colorMode } = useColorMode();
3436

3537
const bottomSheetModalRef = mergeRefs(_ref, ref);
36-
const { children, isOpen, onClose, h, ...rest } = props;
38+
const { children, isOpen, onClose, h, scrollViewProps, ...rest } = props;
3739

3840
useEffect(() => {
3941
if (isOpen) {
@@ -93,13 +95,15 @@ export const DraggableModal = forwardRef<
9395
backgroundStyle={bottomSheetBackgroundStyleObject as ViewStyle}
9496
handleIndicatorStyle={handleStyleObject}
9597
>
96-
<ficus.BottomSheetView {...rest}>
97-
<Box h={h ?? '100%'}>
98-
<SafeAreaView style={safeAreaViewStyle}>
99-
{children as ReactNode}
100-
</SafeAreaView>
101-
</Box>
102-
</ficus.BottomSheetView>
98+
<BottomSheetScrollView {...scrollViewProps}>
99+
<ficus.BottomSheetView {...rest}>
100+
<Box h={h ?? '100%'}>
101+
<SafeAreaView style={safeAreaViewStyle}>
102+
{children as ReactNode}
103+
</SafeAreaView>
104+
</Box>
105+
</ficus.BottomSheetView>
106+
</BottomSheetScrollView>
103107
</ficus.BottomSheetModal>
104108
);
105109
});

0 commit comments

Comments
 (0)