Skip to content

Commit 47edcaf

Browse files
authored
Merge pull request #64 from dohooo/fix63
fix: scroll pass the last item
2 parents a54a825 + 34a5e57 commit 47edcaf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Carousel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function Carousel<T>(
247247
infinite={loop}
248248
translation={handlerOffsetX}
249249
style={style}
250-
max={data.length * size}
250+
maxPage={data.length}
251251
size={size}
252252
panGestureHandlerProps={panGestureHandlerProps}
253253
onScrollBegin={scrollViewGestureOnScrollBegin}

src/ScrollViewGesture.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface Props {
3535

3636
translation: Animated.SharedValue<number>;
3737
size: number;
38-
max: number;
38+
maxPage: number;
3939
}
4040

4141
const IScrollViewGesture: React.FC<Props> = (props) => {
@@ -49,7 +49,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
4949
onScrollBegin,
5050
onScrollEnd,
5151
size,
52-
max,
52+
maxPage,
5353
} = props;
5454

5555
const isHorizontal = useDerivedValue(() => !vertical, [vertical]);
@@ -87,11 +87,11 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
8787
Math.max(page - 1, velocityPage)
8888
);
8989
if (!infinite) {
90-
finalPage = Math.min(max - 1, Math.max(0, finalPage));
90+
finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));
9191
}
9292
translation.value = endWithSpring(-finalPage * size, onFinished);
9393
},
94-
[infinite, endWithSpring, translation, scrollEndVelocity, size, max]
94+
[infinite, endWithSpring, translation, scrollEndVelocity, size, maxPage]
9595
);
9696

9797
const resetBoundary = React.useCallback(() => {
@@ -125,13 +125,13 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
125125
}
126126
}
127127

128-
if (translation.value < -(max - size)) {
128+
if (translation.value < -((maxPage - 1) * size)) {
129129
if (scrollEndTranslation.value > 0) {
130130
activeDecay();
131131
return;
132132
}
133133
if (!infinite) {
134-
translation.value = endWithSpring(-(max - size));
134+
translation.value = endWithSpring(-((maxPage - 1) * size));
135135
return;
136136
}
137137
}
@@ -143,7 +143,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
143143
scrollEndTranslation,
144144
scrollEndVelocity,
145145
onScrollEnd,
146-
max,
146+
maxPage,
147147
size,
148148
]);
149149

@@ -166,7 +166,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
166166
touching.value = true;
167167
cancelAnimation(translation);
168168
onScrollBegin && runOnJS(onScrollBegin)();
169-
ctx.max = max - size;
169+
ctx.max = (maxPage - 1) * size;
170170
ctx.panOffset = translation.value;
171171
},
172172
onActive: (e, ctx) => {
@@ -214,7 +214,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
214214
}
215215
},
216216
},
217-
[pagingEnabled, isHorizontal.value, infinite, max, size]
217+
[pagingEnabled, isHorizontal.value, infinite, maxPage, size]
218218
);
219219

220220
const directionStyle = React.useMemo(() => {

0 commit comments

Comments
 (0)