Skip to content

Commit 6587143

Browse files
author
Stephan Brandt
committed
Fix: Scroll interval and scoll duration should not be necessarily be the same time interval
1 parent 43d5beb commit 6587143

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Carousel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { PropsWithChildren } from 'react';
22
import Animated, { runOnJS, useDerivedValue } from 'react-native-reanimated';
3+
34
import { useCarouselController } from './hooks/useCarouselController';
45
import { useAutoPlay } from './hooks/useAutoPlay';
56
import { usePropsErrorBoundary } from './hooks/usePropsErrorBoundary';
67
import { ScrollViewGesture } from './ScrollViewGesture';
78
import { useVisibleRanges } from './hooks/useVisibleRanges';
9+
810
import type { ICarouselInstance, TCarouselProps } from './types';
911
import { StyleSheet, View } from 'react-native';
1012
import { DATA_LENGTH } from './constants';
@@ -33,6 +35,7 @@ function Carousel<T>(
3335
windowSize,
3436
autoPlayReverse,
3537
autoPlayInterval,
38+
scrollAnimationDuration,
3639
renderItem,
3740
onScrollEnd,
3841
onSnapToItem,
@@ -67,7 +70,7 @@ function Carousel<T>(
6770
onScrollEnd: () => runOnJS(_onScrollEnd)(),
6871
onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),
6972
onChange: (i) => onSnapToItem && runOnJS(onSnapToItem)(i),
70-
duration: autoPlayInterval,
73+
duration: scrollAnimationDuration,
7174
});
7275

7376
const {

src/hooks/useInitProps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function useInitProps<T>(
1717
data: _data = [],
1818
loop = true,
1919
autoPlayInterval = 1000,
20+
scrollAnimationDuration = 500,
2021
style = {},
2122
panGestureHandlerProps = {},
2223
pagingEnabled = true,
@@ -55,6 +56,7 @@ export function useInitProps<T>(
5556
data,
5657
loop,
5758
autoPlayInterval,
59+
scrollAnimationDuration,
5860
style,
5961
panGestureHandlerProps,
6062
pagingEnabled,

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ export type TCarouselProps<T = any> = {
7171
* @description playback interval
7272
*/
7373
autoPlayInterval?: number;
74+
/**
75+
* Time a scroll animation takes to finish
76+
* @default 500 (ms)
77+
*/
78+
scrollAnimationDuration?:number;
7479
/**
7580
* Carousel container style
7681
*/

0 commit comments

Comments
 (0)