@@ -25,8 +25,10 @@ type GestureContext = {
2525interface Props {
2626 size : number ;
2727 infinite ?: boolean ;
28- onScrollEnd ?: ( ) => void ;
2928 onScrollBegin ?: ( ) => void ;
29+ onScrollEnd ?: ( ) => void ;
30+ onTouchBegin ?: ( ) => void ;
31+ onTouchEnd ?: ( ) => void ;
3032 style ?: StyleProp < ViewStyle > ;
3133 translation : Animated . SharedValue < number > ;
3234}
@@ -45,7 +47,14 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
4547 } ,
4648 } = React . useContext ( CTX ) ;
4749
48- const { translation, onScrollBegin, onScrollEnd, size } = props ;
50+ const {
51+ translation,
52+ size,
53+ onScrollBegin,
54+ onScrollEnd,
55+ onTouchBegin,
56+ onTouchEnd,
57+ } = props ;
4958
5059 const maxPage = data . length ;
5160 const isHorizontal = useDerivedValue ( ( ) => ! vertical , [ vertical ] ) ;
@@ -116,22 +125,28 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
116125 ]
117126 ) ;
118127
119- const resetBoundary = React . useCallback ( ( ) => {
120- 'worklet' ;
121- const onFinish = ( isFinished : boolean ) => {
128+ const onFinish = React . useCallback (
129+ ( isFinished : boolean ) => {
130+ 'worklet' ;
122131 if ( isFinished ) {
123132 touching . value = false ;
124133 onScrollEnd && runOnJS ( onScrollEnd ) ( ) ;
125134 }
126- } ;
127- const activeDecay = ( ) => {
128- touching . value = true ;
129- translation . value = withDecay (
130- { velocity : scrollEndVelocity . value } ,
131- onFinish
132- ) ;
133- } ;
135+ } ,
136+ [ onScrollEnd , touching ]
137+ ) ;
138+
139+ const activeDecay = React . useCallback ( ( ) => {
140+ 'worklet' ;
141+ touching . value = true ;
142+ translation . value = withDecay (
143+ { velocity : scrollEndVelocity . value } ,
144+ onFinish
145+ ) ;
146+ } , [ onFinish , scrollEndVelocity . value , touching , translation ] ) ;
134147
148+ const resetBoundary = React . useCallback ( ( ) => {
149+ 'worklet' ;
135150 if ( touching . value ) {
136151 return ;
137152 }
@@ -158,15 +173,14 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
158173 }
159174 }
160175 } , [
161- infinite ,
162- touching ,
163- _withSpring ,
176+ touching . value ,
164177 translation ,
165- scrollEndTranslation ,
166- scrollEndVelocity ,
167- onScrollEnd ,
168178 maxPage ,
169179 size ,
180+ scrollEndTranslation . value ,
181+ infinite ,
182+ activeDecay ,
183+ _withSpring ,
170184 ] ) ;
171185
172186 useAnimatedReaction (
@@ -176,7 +190,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
176190 resetBoundary ( ) ;
177191 }
178192 } ,
179- [ pagingEnabled ]
193+ [ pagingEnabled , resetBoundary ]
180194 ) ;
181195
182196 const panGestureEventHandler = useAnimatedGestureHandler <
@@ -227,15 +241,28 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
227241 }
228242 } ,
229243 } ,
230- [ pagingEnabled , isHorizontal . value , infinite , maxPage , size , enableSnap ]
244+ [
245+ pagingEnabled ,
246+ isHorizontal . value ,
247+ infinite ,
248+ maxPage ,
249+ size ,
250+ enableSnap ,
251+ onScrollBegin ,
252+ onScrollEnd ,
253+ ]
231254 ) ;
232255
233256 const directionStyle = React . useMemo ( ( ) => {
234257 return vertical ? styles . contentHorizontal : styles . contentVertical ;
235258 } , [ vertical ] ) ;
236259
237260 return (
238- < Animated . View style = { [ styles . container , directionStyle , style ] } >
261+ < Animated . View
262+ style = { [ styles . container , directionStyle , style ] }
263+ onTouchStart = { onTouchBegin }
264+ onTouchEnd = { onTouchEnd }
265+ >
239266 < PanGestureHandler
240267 { ...panGestureHandlerProps }
241268 onGestureEvent = { panGestureEventHandler }
0 commit comments