From 4caa8d5da6c6b44d57498be23b89528fb1d810a2 Mon Sep 17 00:00:00 2001 From: rgommezz Date: Sun, 10 May 2020 15:06:43 +0100 Subject: [PATCH] fix: snapPoint edge cases --- src/index.tsx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 53c5131..148a592 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -219,11 +219,22 @@ export class ScrollBottomSheet extends Component> { const didHandleGestureBegin = eq(handleGestureState, GestureState.ACTIVE); - const scrollY = cond( - didHandleGestureBegin, - [set(dragWithHandle, 1), 0], - cond(eq(dragWithHandle, 1), 0, lastStartScrollY) - ); + const scrollY = [ + cond(didHandleGestureBegin, [set(dragWithHandle, 1), 0]), + cond( + and( + eq(dragWithHandle, 1), + greaterThan(snapPoints[0], sub(lastSnap, abs(dragY))), + not(eq(lastSnap, snapPoints[0])) + ), + [ + set(lastSnap, snapPoints[0]), + set(dragWithHandle, 0), + lastStartScrollY, + ], + cond(eq(dragWithHandle, 1), 0, lastStartScrollY) + ), + ]; const isAnimationInterrupted = and( or( @@ -355,6 +366,7 @@ export class ScrollBottomSheet extends Component> { set(prevTranslateYOffset, animationPosition), set(animationFinished, 1), stopClock(animationClock), + set(lastSnap, animationPosition), animationPosition, ]), cond(