1
- import React , { useMemo , useRef , memo } from 'react' ;
1
+ import React , { useMemo , memo } from 'react' ;
2
2
import Animated from 'react-native-reanimated' ;
3
- import { PanGestureHandler } from 'react-native-gesture-handler' ;
3
+ import { GestureDetector , Gesture } from 'react-native-gesture-handler' ;
4
4
import {
5
5
useBottomSheetGestureHandlers ,
6
6
useBottomSheetInternal ,
7
7
} from '../../hooks' ;
8
- import { GESTURE_SOURCE } from '../../constants' ;
9
8
import type { BottomSheetDraggableViewProps } from './types' ;
9
+ import { BottomSheetDraggableContext } from '../../contexts/gesture' ;
10
10
11
11
const BottomSheetDraggableViewComponent = ( {
12
- gestureType = GESTURE_SOURCE . CONTENT ,
13
12
nativeGestureRef,
14
13
refreshControlGestureRef,
15
14
style,
@@ -26,19 +25,10 @@ const BottomSheetDraggableViewComponent = ({
26
25
failOffsetX,
27
26
failOffsetY,
28
27
} = useBottomSheetInternal ( ) ;
29
- const { contentPanGestureHandler, scrollablePanGestureHandler } =
30
- useBottomSheetGestureHandlers ( ) ;
28
+ const { contentPanGestureHandler } = useBottomSheetGestureHandlers ( ) ;
31
29
//#endregion
32
30
33
31
//#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
- ) ;
42
32
const simultaneousHandlers = useMemo ( ( ) => {
43
33
const refs = [ ] ;
44
34
@@ -64,25 +54,66 @@ const BottomSheetDraggableViewComponent = ({
64
54
nativeGestureRef ,
65
55
refreshControlGestureRef ,
66
56
] ) ;
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
+ ] ) ;
67
107
//#endregion
68
108
69
109
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 >
86
117
) ;
87
118
} ;
88
119
0 commit comments