Usage#
Here is a simple usage of the React Native Reanimated Carousel. For more scrollable usage please read Scrollables.
<video width="320" height="240" autoPlay loop style={{border:'1px solid gray', margin:"0 auto",borderRadius:10,marginTop:10}}>
import * as React from "react";
import { Dimensions, Text, View } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { useSharedValue } from "react-native-reanimated";
import { Carousel, Pagination, type CarouselRef } from "react-native-reanimated-carousel";
const data = [...new Array(6).keys()];
const width = Dimensions.get("window").width;
function App() {
const ref = React.useRef<CarouselRef>(null);
const progress = useSharedValue<number>(0);
const onPressPagination = (index: number) => {
ref.current?.scrollTo({
index,
animated: true,
});
};
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<Carousel
ref={ref}
style={{ width, height: width / 2 }}
data={data}
progress={progress}
renderItem={({ index }) => (
<View
style={{
flex: 1,
borderWidth: 1,
justifyContent: "center",
}}
<Text style={{ textAlign: "center", fontSize: 30 }}>{index}</Text>
</View>
)}
/>
<Pagination
progress={progress}
count={data.length}
dotStyle={{ backgroundColor: "rgba(0,0,0,0.2)", borderRadius: 50 }}
containerStyle={{ gap: 5, marginTop: 10 }}
onPress={onPressPagination}
getItemAccessibilityLabel={(index, count) => `Main carousel: item ${index + 1} of ${count}`}
/>
</GestureHandlerRootView>
);
}
export default App;
Accessible Pagination#
Use getItemAccessibilityLabel with interactive Pagination when you need contextual or localized labels. The v4 carouselName and paginationItemAccessibility props are ignored; development warnings identify these props and their replacements:
<Pagination
progress={progress}
count={data.length}
onPress={onPressPagination}
getItemAccessibilityLabel={(index, count) => `Go to product ${index + 1} of ${count}`}
/>
Sizing Your Carousel#
The Carousel component supports multiple ways to define its size. Understanding these options helps you achieve the layout you need.
1. Explicit Dimensions (Recommended)#
The most straightforward approach is setting explicit width and height via the style prop:
<Carousel
style={{ width: 300, height: 200 }}
data={data}
renderItem={renderItem}
/>
This gives you full control over the carousel's dimensions and is the most predictable approach.
2. Flex-based Sizing#
You can use flex layout to have the carousel fill its parent container:
<View style={{ flex: 1 }}>
<Carousel
style={{ flex: 1 }}
data={data}
renderItem={renderItem}
/>
</View>
The carousel will measure its container and adapt automatically. This is useful when you want the carousel to respond to its parent's layout.
3. Custom Snap Distance with itemSize#
When you want items smaller than the container with custom snapping behavior, use itemSize for either orientation:
// Container is 400px wide, but snaps every 200px (showing ~2 items)
<Carousel
style={{ width: 400, height: 200 }}
itemSize={200}
data={data}
renderItem={renderItem}
/>
This is particularly useful for:
- Showing multiple items at once
- Implementing "peek" effects where adjacent items are partially visible
- Custom snap intervals independent of container size
4. Ignored Legacy Props#
The v4 width, height, itemWidth, itemHeight and vertical props are ignored. Use style.width / style.height, itemSize and orientation="vertical" instead.
In development, Carousel and Pagination warn once per ignored v4 prop per component instance, naming the replacement and pointing to npx --yes rnrc-codemod v5 . and the migration guide. Production builds skip these warnings. Pagination requires a non-negative integer count; in development, its invalid-count error also identifies ignored v4 props such as data.
Sizing Summary#
| Scenario | Props to Use | Example |
|---|---|---|
| Fixed size | style={{ width, height }} | style={{ width: 300, height: 200 }} |
| Fill parent | style={{ flex: 1 }} | Parent must have defined size |
| Custom snap | style + itemSize | style={{ width: 400 }} itemSize={200} |
| Vertical | style + orientation | style={{ height: 400 }} orientation="vertical" |
Important Notes#
-
At least one dimension is required: The carousel needs to know its size either through explicit dimensions in
styleor flex layout. -
For horizontal carousels: Width is the primary dimension that controls snapping.
-
For vertical carousels: Height is the primary dimension that controls snapping.
-
Performance: The carousel waits for layout measurement before rendering items. With
style={{ flex: 1 }}, there may be a brief moment before items appear as the component measures its container.