From 8017fb6b02088d3c66c64a8a23e0f63f22884d36 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Wed, 3 Jan 2024 19:22:41 +0100 Subject: [PATCH] feat: added default dynamic sizing (#1513)(with @Eli-Nathan & @ororsatti) (#1683) --- .../advanced/DynamicSnapPointExample.tsx | 32 +++--- .../screens/modal/DynamicSnapPointExample.tsx | 32 +++--- src/components/bottomSheet/BottomSheet.tsx | 70 ++++++------ src/components/bottomSheet/constants.ts | 2 + src/components/bottomSheet/types.d.ts | 33 +++--- .../bottomSheetModal/BottomSheetModal.tsx | 9 +- .../createBottomSheetScrollableComponent.tsx | 22 +++- .../bottomSheetView/BottomSheetView.tsx | 34 +++++- src/constants.ts | 6 + src/contexts/internal.ts | 1 + src/hooks/index.ts | 1 - src/hooks/useBottomSheetDynamicSnapPoints.ts | 61 ----------- src/hooks/useNormalizedSnapPoints.ts | 103 +++++++++++++----- src/hooks/usePropsValidator.ts | 20 ++-- src/index.ts | 1 - src/utilities/normalizeSnapPoint.ts | 5 +- 16 files changed, 242 insertions(+), 190 deletions(-) delete mode 100644 src/hooks/useBottomSheetDynamicSnapPoints.ts diff --git a/example/src/screens/advanced/DynamicSnapPointExample.tsx b/example/src/screens/advanced/DynamicSnapPointExample.tsx index fb9340225..724818918 100644 --- a/example/src/screens/advanced/DynamicSnapPointExample.tsx +++ b/example/src/screens/advanced/DynamicSnapPointExample.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react'; import { View, StyleSheet, Text } from 'react-native'; import BottomSheet, { BottomSheetView, - useBottomSheetDynamicSnapPoints, + SNAP_POINT_TYPE, } from '@gorhom/bottom-sheet'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Button } from '../../components/button'; @@ -10,19 +10,12 @@ import { Button } from '../../components/button'; const DynamicSnapPointExample = () => { // state const [count, setCount] = useState(0); - const initialSnapPoints = useMemo(() => ['CONTENT_HEIGHT'], []); // hooks const { bottom: safeBottomArea } = useSafeAreaInsets(); const bottomSheetRef = useRef(null); - const { - animatedHandleHeight, - animatedSnapPoints, - animatedContentHeight, - handleContentLayout, - } = useBottomSheetDynamicSnapPoints(initialSnapPoints); - // callbacks + //#region callbacks const handleIncreaseContentPress = useCallback(() => { setCount(state => state + 1); }, []); @@ -35,8 +28,16 @@ const DynamicSnapPointExample = () => { const handleClosePress = useCallback(() => { bottomSheetRef.current?.close(); }, []); + const handleSheetChange = useCallback( + (index: number, position: number, type: SNAP_POINT_TYPE) => { + // eslint-disable-next-line no-console + console.log('handleSheetChange', { index, position, type }); + }, + [] + ); + //#endregion - // styles + //#region styles const contentContainerStyle = useMemo( () => [ styles.contentContainerStyle, @@ -51,6 +52,7 @@ const DynamicSnapPointExample = () => { }), [count] ); + //#endregion // renders return ( @@ -59,16 +61,12 @@ const DynamicSnapPointExample = () => {