Skip to content

Commit 853c754

Browse files
authored
Merge pull request #103 from contagt/develop
Add: Scroll Duration Prop
2 parents cd25ad8 + bbea6cd commit 853c754

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

docs/props.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
| defaultIndex || 0 | number | Default index |
1414
| autoPlay || false | boolean | Auto play |
1515
| autoPlayReverse || false | boolean | Auto play reverse playback |
16-
| autoPlayInterval || 1000 | autoPlayInterval | Auto play playback interval |
16+
| autoPlayInterval || 1000 | number | Auto play playback interval |
17+
| scrollAnimationDuration || 500 | number | Time a scroll animation takes to finish |
1718
| loop || true | boolean | Carousel loop playback |
1819
| onSnapToItem || | (index: number) => void | Callback fired when navigating to an item |
1920
| onScrollBegin || | () => void | Callback fired when scroll begin |

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)