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 25, 2022
1 parent 0984edf commit d224185
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 d224185

Please sign in to comment.