1- import { useCallback , useEffect , useRef , MutableRefObject } from 'react' ;
1+ import { useCallback , useEffect , MutableRefObject } from 'react' ;
22import { NativeScrollEvent , NativeSyntheticEvent , ScrollView } from 'react-native' ;
33
44interface UseTimelineOffsetProps {
@@ -10,8 +10,6 @@ interface UseTimelineOffsetProps {
1010export default ( props : UseTimelineOffsetProps ) => {
1111 const { onChangeOffset, scrollOffset, scrollViewRef} = props ;
1212
13- const inMomentum = useRef ( false ) ;
14-
1513 useEffect ( ( ) => {
1614 // NOTE: The main reason for this feature is to sync the offset
1715 // between all of the timelines in the TimelineList component
@@ -25,29 +23,20 @@ export default (props: UseTimelineOffsetProps) => {
2523
2624 const onScrollEndDrag = useCallback ( ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
2725 const offset = event . nativeEvent . contentOffset . y ;
28- setTimeout ( ( ) => {
29- if ( ! inMomentum . current ) {
30- onChangeOffset ?.( offset ) ;
31- }
32- } , 0 ) ;
33- } , [ ] ) ;
26+ const velocity = event . nativeEvent . velocity ?. y ;
3427
35- const onMomentumScrollBegin = useCallback ( ( ) => {
36- inMomentum . current = true ;
28+ if ( velocity === 0 ) {
29+ onChangeOffset ?.( offset ) ;
30+ }
3731 } , [ ] ) ;
3832
39- const onMomentumScrollEnd = useCallback (
40- ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
41- inMomentum . current = false ;
42- onChangeOffset ?.( event . nativeEvent . contentOffset . y ) ;
43- } ,
44- [ onChangeOffset ]
45- ) ;
33+ const onMomentumScrollEnd = useCallback ( ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
34+ onChangeOffset ?.( event . nativeEvent . contentOffset . y ) ;
35+ } , [ ] ) ;
4636
4737 return {
4838 scrollEvents : {
4939 onScrollEndDrag,
50- onMomentumScrollBegin,
5140 onMomentumScrollEnd
5241 }
5342 } ;
0 commit comments