Skip to content

Commit

Permalink
Cancel animation timer on stop scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Mar 24, 2022
1 parent 36b7ef1 commit 661c350
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default function useScrollWhenDragging() {

const stopScrolling = () => {
'worklet';
cancelAnimation( animationTimer );

isAnimationTimerActive.value = false;
isScrollActive.value = false;
velocityY.value = 0;
Expand Down Expand Up @@ -96,6 +98,10 @@ export default function useScrollWhenDragging() {
useAnimatedReaction(
() => animationTimer.value,
( value, previous ) => {
if ( velocityY.value === 0 ) {
return;
}

const delta = Math.abs( value - previous );
let newOffset = offsetY.value + delta * velocityY.value;

Expand All @@ -110,13 +116,9 @@ export default function useScrollWhenDragging() {
// new offset value.
newOffset = Math.max( 0, newOffset );
}
offsetY.value = newOffset;

if ( velocityY.value !== 0 ) {
scrollTo( animatedScrollRef, 0, offsetY.value, false );
} else if ( ! isAnimationTimerActive.value ) {
cancelAnimation( animationTimer );
}
offsetY.value = newOffset;
scrollTo( animatedScrollRef, 0, offsetY.value, false );
}
);

Expand Down

0 comments on commit 661c350

Please sign in to comment.