UNPKG

@birdwingo/react-native-swipe-modal

Version:

A versatile and smooth swipeable modal component for React Native applications.

31 lines (19 loc) 763 B
import { Gesture, GestureUpdateEvent, PanGestureHandlerEventPayload } from 'react-native-gesture-handler'; import { useSharedValue } from 'react-native-reanimated'; import { useMemo } from 'react'; type Event = GestureUpdateEvent<PanGestureHandlerEventPayload> | undefined; const useGesture = ( ref: any ) => { const event = useSharedValue<Event>( undefined ); // eslint-disable-next-line new-cap const gesture = useMemo( () => Gesture.Pan() .activeOffsetY( [ -10, 10 ] ) .onUpdate( ( e ) => { event.value = e; } ) .onEnd( () => { event.value = undefined; } ), [ event ] ) .simultaneousWithExternalGesture( ref ); return useMemo( () => ( { gesture, event } ), [ gesture, event ] ); }; export { useGesture };