Skip to content

Commit

Permalink
fix: onSnapToItem gives floating index
Browse files Browse the repository at this point in the history
fix #13
  • Loading branch information
dohooo committed Oct 27, 2021
1 parent c9b6eee commit 13d6c64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,30 @@ function Carousel<T extends unknown = any>(
const {
height = '100%',
data: _data = [],
width,
loop = true,
mode = 'default',
renderItem,
autoPlay,
autoPlayReverse,
autoPlayInterval,
autoPlayInterval = 1000,
parallaxScrollingOffset,
parallaxScrollingScale,
onSnapToItem,
style,
timingConfig = defaultTimingConfig,
panGestureHandlerProps = {},
} = props;

if (
typeof timingConfig.duration === 'number' &&
timingConfig.duration > autoPlayInterval
) {
throw Error(
'The during time of animation must less than autoplay interval.'
);
}

const width = Math.round(props.width);
const lockController = useLockController();
const handlerOffsetX = useSharedValue<number>(0);
const data = React.useMemo<T[]>(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useAutoPlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function useAutoPlay(opts: {
const {
autoPlay = false,
autoPlayReverse = false,
autoPlayInterval = 1000,
autoPlayInterval,
carouselController,
} = opts;

Expand Down

0 comments on commit 13d6c64

Please sign in to comment.