1- import React , { useMemo , useRef , memo } from 'react' ;
1+ import React , { useMemo , memo } from 'react' ;
22import Animated from 'react-native-reanimated' ;
3- import { PanGestureHandler } from 'react-native-gesture-handler' ;
3+ import { GestureDetector , Gesture } from 'react-native-gesture-handler' ;
44import {
55 useBottomSheetGestureHandlers ,
66 useBottomSheetInternal ,
77} from '../../hooks' ;
8- import { GESTURE_SOURCE } from '../../constants' ;
98import type { BottomSheetDraggableViewProps } from './types' ;
9+ import { BottomSheetDraggableContext } from '../../contexts/gesture' ;
1010
1111const BottomSheetDraggableViewComponent = ( {
12- gestureType = GESTURE_SOURCE . CONTENT ,
1312 nativeGestureRef,
1413 refreshControlGestureRef,
1514 style,
@@ -26,19 +25,10 @@ const BottomSheetDraggableViewComponent = ({
2625 failOffsetX,
2726 failOffsetY,
2827 } = useBottomSheetInternal ( ) ;
29- const { contentPanGestureHandler, scrollablePanGestureHandler } =
30- useBottomSheetGestureHandlers ( ) ;
28+ const { contentPanGestureHandler } = useBottomSheetGestureHandlers ( ) ;
3129 //#endregion
3230
3331 //#region variables
34- const panGestureRef = useRef < PanGestureHandler > ( null ) ;
35- const gestureHandler = useMemo (
36- ( ) =>
37- gestureType === GESTURE_SOURCE . CONTENT
38- ? contentPanGestureHandler
39- : scrollablePanGestureHandler ,
40- [ gestureType , contentPanGestureHandler , scrollablePanGestureHandler ]
41- ) ;
4232 const simultaneousHandlers = useMemo ( ( ) => {
4333 const refs = [ ] ;
4434
@@ -64,25 +54,66 @@ const BottomSheetDraggableViewComponent = ({
6454 nativeGestureRef ,
6555 refreshControlGestureRef ,
6656 ] ) ;
57+ const draggableGesture = useMemo ( ( ) => {
58+ let gesture = Gesture . Pan ( )
59+ . enabled ( enableContentPanningGesture )
60+ . shouldCancelWhenOutside ( false )
61+ . runOnJS ( false )
62+ . onStart ( contentPanGestureHandler . handleOnStart )
63+ . onChange ( contentPanGestureHandler . handleOnChange )
64+ . onEnd ( contentPanGestureHandler . handleOnEnd )
65+ . onFinalize ( contentPanGestureHandler . handleOnFinalize ) ;
66+
67+ if ( waitFor ) {
68+ gesture = gesture . requireExternalGestureToFail ( waitFor ) ;
69+ }
70+
71+ if ( simultaneousHandlers ) {
72+ gesture = gesture . simultaneousWithExternalGesture (
73+ simultaneousHandlers as any
74+ ) ;
75+ }
76+
77+ if ( activeOffsetX ) {
78+ gesture = gesture . activeOffsetX ( activeOffsetX ) ;
79+ }
80+
81+ if ( activeOffsetY ) {
82+ gesture = gesture . activeOffsetY ( activeOffsetY ) ;
83+ }
84+
85+ if ( failOffsetX ) {
86+ gesture = gesture . failOffsetX ( failOffsetX ) ;
87+ }
88+
89+ if ( failOffsetY ) {
90+ gesture = gesture . failOffsetY ( failOffsetY ) ;
91+ }
92+
93+ return gesture ;
94+ } , [
95+ activeOffsetX ,
96+ activeOffsetY ,
97+ enableContentPanningGesture ,
98+ failOffsetX ,
99+ failOffsetY ,
100+ simultaneousHandlers ,
101+ waitFor ,
102+ contentPanGestureHandler . handleOnChange ,
103+ contentPanGestureHandler . handleOnEnd ,
104+ contentPanGestureHandler . handleOnFinalize ,
105+ contentPanGestureHandler . handleOnStart ,
106+ ] ) ;
67107 //#endregion
68108
69109 return (
70- < PanGestureHandler
71- ref = { panGestureRef }
72- enabled = { enableContentPanningGesture }
73- simultaneousHandlers = { simultaneousHandlers }
74- shouldCancelWhenOutside = { false }
75- waitFor = { waitFor }
76- onGestureEvent = { gestureHandler }
77- activeOffsetX = { activeOffsetX }
78- activeOffsetY = { activeOffsetY }
79- failOffsetX = { failOffsetX }
80- failOffsetY = { failOffsetY }
81- >
82- < Animated . View style = { style } { ...rest } >
83- { children }
84- </ Animated . View >
85- </ PanGestureHandler >
110+ < GestureDetector gesture = { draggableGesture } >
111+ < BottomSheetDraggableContext . Provider value = { draggableGesture } >
112+ < Animated . View style = { style } { ...rest } >
113+ { children }
114+ </ Animated . View >
115+ </ BottomSheetDraggableContext . Provider >
116+ </ GestureDetector >
86117 ) ;
87118} ;
88119
0 commit comments