From b5fc081fe0f2617ee63f31ac6dcabc6715d465e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=9D=B1=E6=BE=94?= Date: Tue, 28 Jun 2022 20:28:49 +0800 Subject: [PATCH] fix: carousel crashes when swiping in the opposite direction fix #215 --- src/ScrollViewGesture.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ScrollViewGesture.tsx b/src/ScrollViewGesture.tsx index ea034aaf..dfceabe3 100644 --- a/src/ScrollViewGesture.tsx +++ b/src/ScrollViewGesture.tsx @@ -113,9 +113,7 @@ const IScrollViewGesture: React.FC = (props) => { return; } - const direction = - -scrollEndTranslation.value / - Math.abs(scrollEndTranslation.value); + const direction = -(scrollEndTranslation.value >= 0 ? 1 : -1); const computed = direction < 0 ? Math.ceil : Math.floor; const page = computed(-translation.value / size); let finalPage = page + direction;