From 1ce57f4e0201c2d50a1ce754f08b6afb5661a6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=9D=B1=E6=BE=94?= Date: Fri, 8 Oct 2021 14:35:43 +0800 Subject: [PATCH] fix: onSnapToItem not called if loop={false} --- example/src/App.tsx | 1 + src/Carousel.tsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 7b27c3be..b038f002 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -34,6 +34,7 @@ export default function App() { mode="parallax" width={width} data={data} + loop={false} parallaxScrollingScale={0.8} onSnapToItem={(index) => { console.log('current index:', index); diff --git a/src/Carousel.tsx b/src/Carousel.tsx index be7d00b6..b6754b0d 100644 --- a/src/Carousel.tsx +++ b/src/Carousel.tsx @@ -193,8 +193,9 @@ function Carousel( i = i % 2; break; } - onSnapToItem && runOnJS(onSnapToItem)(i); } + + onSnapToItem && runOnJS(onSnapToItem)(i); }, [onSnapToItem, loop, _data] );