From db8c802c271453309cae825b08e2ea2bf397f64c Mon Sep 17 00:00:00 2001 From: Dawid van der Hoven Date: Wed, 27 Jan 2021 13:19:39 +0100 Subject: [PATCH 01/11] feat: add a bottom inset option --- src/components/bottomSheet/BottomSheet.tsx | 19 +++++++++++++------ src/components/bottomSheet/types.d.ts | 7 +++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index d6c21b1c2..eb69f3d8d 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -26,9 +26,11 @@ import Animated, { sub, abs, greaterThan, + concat, } from 'react-native-reanimated'; import { PanGestureHandler, State } from 'react-native-gesture-handler'; import { + ReText, usePanGestureHandler, // ReText, } from 'react-native-redash'; @@ -84,6 +86,7 @@ const BottomSheetComponent = forwardRef( snapPoints: _snapPoints, handleHeight: _handleHeight, topInset = 0, + bottomInset = 0, enableContentPanningGesture = DEFAULT_ENABLE_CONTENT_PANNING_GESTURE, enableHandlePanningGesture = DEFAULT_ENABLE_HANDLE_PANNING_GESTURE, animateOnMount = DEFAULT_ANIMATE_ON_MOUNT, @@ -301,10 +304,14 @@ const BottomSheetComponent = forwardRef( () => ({ ...styles.container, transform: [ - { translateY: isLayoutCalculated ? position : containerHeight }, + { + translateY: isLayoutCalculated + ? sub(position, bottomInset) + : containerHeight, + }, ], }), - [containerHeight, position, isLayoutCalculated] + [containerHeight, position, isLayoutCalculated, bottomInset] ); const contentContainerStyle = useMemo( () => ({ @@ -579,7 +586,7 @@ const BottomSheetComponent = forwardRef( exec={set(_animatedIndexCallbackNode, animatedIndex)} /> )} - {/* + ( style={styles.debugText} text={concat('position: ', position)} /> - - */} + /> */} + ); //#endregion diff --git a/src/components/bottomSheet/types.d.ts b/src/components/bottomSheet/types.d.ts index f6bc9e35f..6ef31f70c 100644 --- a/src/components/bottomSheet/types.d.ts +++ b/src/components/bottomSheet/types.d.ts @@ -43,6 +43,13 @@ export type BottomSheetProps = { * @default 0 */ topInset?: number; + /** + * Bottom inset value helps to calculate percentage snap points values, + * usually comes from `@react-navigation/stack` hook `useHeaderHeight` or from `react-native-safe-area-context` hook `useSafeArea`. + * @type number + * @default 0 + */ + bottomInset?: number; /** * Enable content panning gesture interaction. * @type boolean From 6f663b78f628ef5f4874a137a23f33f241fe4679 Mon Sep 17 00:00:00 2001 From: Dawid van der Hoven Date: Wed, 27 Jan 2021 13:31:08 +0100 Subject: [PATCH 02/11] fix: remove debug --- src/components/bottomSheet/BottomSheet.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index eb69f3d8d..36e80c704 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -26,11 +26,9 @@ import Animated, { sub, abs, greaterThan, - concat, } from 'react-native-reanimated'; import { PanGestureHandler, State } from 'react-native-gesture-handler'; import { - ReText, usePanGestureHandler, // ReText, } from 'react-native-redash'; @@ -586,7 +584,7 @@ const BottomSheetComponent = forwardRef( exec={set(_animatedIndexCallbackNode, animatedIndex)} /> )} - + {/* ( style={styles.debugText} text={concat('position: ', position)} /> - {/* */} - + /> + */} ); //#endregion From 8144efbfc2ddb6cd72dc65d26156714578927915 Mon Sep 17 00:00:00 2001 From: Dawid van der Hoven Date: Thu, 4 Feb 2021 14:05:05 +0100 Subject: [PATCH 03/11] feat: add footer example and fix modal behaviour --- example/src/App.tsx | 9 + example/src/screens/Root.tsx | 4 + .../modal/StackWithBottomInsetExample.tsx | 179 ++++++++++++++++++ example/src/types.ts | 1 + .../bottomSheetModal/BottomSheetModal.tsx | 4 +- 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 example/src/screens/modal/StackWithBottomInsetExample.tsx diff --git a/example/src/App.tsx b/example/src/App.tsx index ae75d818f..edd2521ae 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -78,6 +78,15 @@ const App = () => { }} getComponent={() => require('./screens/modal/StackExample').default} /> + + require('./screens/modal/StackWithBottomInsetExample').default + } + /> { + // hooks + const { dismiss, dismissAll } = useBottomSheetModal(); + + // refs + const bottomSheetModalARef = useRef(null); + const bottomSheetModalBRef = useRef(null); + const bottomSheetModalCRef = useRef(null); + + // variables + const snapPoints = useMemo(() => ['25%', '50%'], []); + + // callbacks + const handlePresentAPress = useCallback(() => { + if (bottomSheetModalARef.current) { + bottomSheetModalARef.current.present(); + } + }, []); + const handleDismissAPress = useCallback(() => { + if (bottomSheetModalARef.current) { + bottomSheetModalARef.current.dismiss(); + } + }, []); + const handlePresentBPress = useCallback(() => { + if (bottomSheetModalBRef.current) { + bottomSheetModalBRef.current.present(); + } + }, []); + const handleDismissBPress = useCallback(() => { + if (bottomSheetModalBRef.current) { + bottomSheetModalBRef.current.dismiss(); + } + }, []); + const handlePresentCPress = useCallback(() => { + if (bottomSheetModalCRef.current) { + bottomSheetModalCRef.current.present(); + } + }, []); + const handleDismissCPress = useCallback(() => { + if (bottomSheetModalCRef.current) { + bottomSheetModalCRef.current.dismiss(); + } + }, []); + const handleDismissAllPress = useCallback(() => { + dismissAll(); + }, [dismissAll]); + + const handleDismissByHookPress = useCallback(() => { + dismiss('A'); + }, [dismiss]); + + // renders + + const renderBottomSheetContent = useCallback( + (title, onPress) => ( + + ), + [] + ); + return ( + <> + +