import { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from 'react'; import { BottomSheetBackdrop, BottomSheetModal, useBottomSheetDynamicSnapPoints } from '@gorhom/bottom-sheet'; import { useReducedMotion } from 'react-native-reanimated'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { AppBox } from '../../layout/AppBox'; import { useAppTheme } from '~/view/theme'; export type AppBottomSheetRefHanldes = { show: () => void; hide: () => void; }; type SnapMode = 'full-height' | 'content-height'; type Props = { children: React.ReactNode[] | React.ReactNode; onDismiss?: () => void; snapMode?: SnapMode; handleBackground?: any; androidInputMode?: 'adjustPan' | 'adjustResize'; }; export const AppBottomSheet = forwardRef( ( { snapMode = 'content-height', children, onDismiss, handleBackground, androidInputMode = 'adjustResize' }, ref ) => { const insets = useSafeAreaInsets(); const { spacing, otherSizes, colors } = useAppTheme(); const bottomSheetModalRef = useRef(null); // https://github.com/gorhom/react-native-bottom-sheet/issues/1560 const reducedMotion = useReducedMotion(); const initialSnapPoints = useMemo( () => (snapMode === 'content-height' ? ['CONTENT_HEIGHT'] : ['100%']), [snapMode] ); const { animatedHandleHeight, animatedSnapPoints, animatedContentHeight, handleContentLayout } = useBottomSheetDynamicSnapPoints(initialSnapPoints); useImperativeHandle(ref, () => ({ show: () => { bottomSheetModalRef.current?.present(); }, hide: () => { bottomSheetModalRef.current?.dismiss(); } })); const renderBackDrop = useCallback( (props: any) => ( ), [] ); const renderHandle = useCallback( () => ( ), [] ); const bottomInset = insets.bottom ? insets.bottom : spacing.s; const topInset = insets.top ? insets.top : spacing.s; return ( {children} ); } );