Skip to content

Commit 03216a5

Browse files
committed
feat: always return the real index
re #192
1 parent ef30a72 commit 03216a5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Carousel.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,27 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
9797
const _onScrollEnd = React.useCallback(() => {
9898
const _sharedIndex = Math.round(getSharedIndex());
9999

100+
const realIndex = computedRealIndexWithAutoFillData({
101+
index: _sharedIndex,
102+
dataLength: rawData.length,
103+
loop,
104+
autoFillData,
105+
});
106+
100107
if (onSnapToItem) {
101-
onSnapToItem(_sharedIndex);
108+
onSnapToItem(realIndex);
102109
}
103110
if (onScrollEnd) {
104-
onScrollEnd(_sharedIndex);
111+
onScrollEnd(realIndex);
105112
}
106-
}, [onSnapToItem, onScrollEnd, getSharedIndex]);
113+
}, [
114+
loop,
115+
autoFillData,
116+
rawData.length,
117+
getSharedIndex,
118+
onSnapToItem,
119+
onScrollEnd,
120+
]);
107121

108122
const scrollViewGestureOnScrollBegin = React.useCallback(() => {
109123
pauseAutoPlay();

0 commit comments

Comments
 (0)