Skip to content

Commit 5fde11a

Browse files
committed
Fix issue with syncing timelines offset
1 parent bf6e61f commit 5fde11a

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/timeline-list/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const TimelineList = (props: TimelineListProps) => {
120120
scrollToNow: _isToday && isInitialPage && scrollToNow,
121121
initialTime: !_isToday && isInitialPage ? initialTime : undefined,
122122
scrollToFirst: !_isToday && isInitialPage && scrollToFirst,
123-
scrollOffset: isCurrent ? undefined : timelineOffset,
123+
scrollOffset: timelineOffset,
124124
onChangeOffset: onTimelineOffsetChange,
125125
showNowIndicator: _isToday && showNowIndicator
126126
};

src/timeline/useTimelineOffset.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useEffect, useRef, MutableRefObject} from 'react';
1+
import {useCallback, useEffect, MutableRefObject} from 'react';
22
import {NativeScrollEvent, NativeSyntheticEvent, ScrollView} from 'react-native';
33

44
interface UseTimelineOffsetProps {
@@ -10,8 +10,6 @@ interface UseTimelineOffsetProps {
1010
export 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

Comments
 (0)