tapcn
Components

Carousel

A horizontal swipeable carousel with snap-to-item behavior.

Carousel

A horizontal swipeable carousel that renders a list of items with snap-to-item scrolling, dot indicators, and optional auto-play. Built on top of React Native's ScrollView with snap interval support.

Installation

npx @tapcn/cli add carousel

Or using shadcn directly:

npx shadcn@latest add https://tapcn.vercel.app/r/carousel.json

Usage

import { Carousel } from '~/components/ui/carousel';
import { View, Text } from 'react-native';

const slides = [
  { id: '1', title: 'Welcome' },
  { id: '2', title: 'Explore' },
  { id: '3', title: 'Get Started' },
];

export function CarouselExample() {
  return (
    <Carousel
      data={slides}
      renderItem={(item, index) => (
        <View className="h-48 items-center justify-center rounded-xl bg-muted">
          <Text className="text-lg font-semibold text-foreground">{item.title}</Text>
        </View>
      )}
    />
  );
}

With auto-play

<Carousel
  data={slides}
  renderItem={(item) => (
    <View className="h-48 items-center justify-center rounded-xl bg-muted">
      <Text className="text-foreground">{item.title}</Text>
    </View>
  )}
  autoPlay
  autoPlayInterval={5000}
/>

Without indicators

<Carousel
  data={slides}
  renderItem={(item) => (/* ... */)}
  showIndicators={false}
/>

Props

PropTypeDefaultDescription
dataT[]requiredThe array of items to render in the carousel.
renderItem(item: T, index: number) => React.ReactNoderequiredRender function called for each item.
itemWidthnumberscreenWidth - 32The width of each carousel item in pixels.
gapnumber16The horizontal gap between items in pixels.
showIndicatorsbooleantrueWhether to show the dot indicators below the carousel.
autoPlaybooleanfalseWhether the carousel should automatically advance.
autoPlayIntervalnumber4000The interval in milliseconds between auto-play advances.
classNamestring-Additional NativeWind classes for the outer container.

Dependencies

No additional dependencies.

On this page