Carousel
Native paging with overlay navigation, thumbnails and opt-in automatic playback.
npx @swipeui/cli add carouselWhen to use it
- Onboarding slides, feature tours or photo galleries that people swipe through.
- Horizontal paging of cards with page dots below.
- A small set of promotions where each page fills the width.
When not to use it
- Important content people might miss on later pages.
- Automatic rotation without an accessible pause/resume control.
- Long product lists. Use a horizontal list or grid.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add carousel- Adds
components/swipeui/ui/use-carousel-autoplay.ts,components/swipeui/ui/carousel.tsxand 8 shared helpers. - Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { Carousel } from '@/components/swipeui/ui/carousel';
<Carousel pages={pages} />;API reference
| Prop | Type | Default | Description |
|---|---|---|---|
pageAspectRatio? | | — | Constrain the page viewport to width / height; omit for intrinsic content. |
navigationPlacement? | | | Position navigation over the page or below it. |
autoPlay? | | | Opt-in automatic page changes. |
autoPlayInterval? | | | Time each page is held, in milliseconds, at least 1000. |
loop? | | | Wrap from the last page to the first. |
paused? | | — | Controlled user pause state. Focus/hover/preferences may suspend independently. |
defaultPaused? | | | Initial user pause state. |
onPausedChange? | | — | Reports explicit playback changes. |
showPlaybackControl? | | | Show a named playback toggle when autoPlay is enabled. |
showThumbnails? | | | Show the caller-supplied thumbnail strip. |
thumbnailSize? | | | Thumbnail frame in points, at least 44. |
showIndicators? | | | Show page markers or a translated count. |
showNavigation? | | | Show previous/next controls. |
maxIndicators? | | | Maximum dots before switching to a count, 1–50. |
haptics? | | | Navigation feedback. |
messages? | | — | Text overrides; empty overrides legacy emptyLabel. |
pages | | — | Pages in reading order. |
emptyLabel? | | | Empty collection label. |
index? | | — | Controlled page index. |
defaultIndex? | | | Initial page index. |
onIndexChange? | | — | Reports navigation intent, including automatic progression. |
motion? | | — | Indicator/press character; reduced motion disables automatic rotation. |
className? | | — | Root classes. |
style? | | — | Root layout escape hatch. |
testID? | | — | Root identifier. |
Composition and behavior
- pages in reading order, each with an id and content.
- Page dots below for navigation; emptyLabel for no pages.
- Control with index and onIndexChange, or defaultIndex.
- Supply thumbnail on each page and enable showThumbnails for a preview strip.
- autoPlay is opt-in, with autoPlayInterval, loop and independent pause state. Focus/manual interaction stops rotation until explicit resume; reduced motion and native screen readers suspend it.
Behavior and gestures
- Manual paging by swipe, named arrows, page markers or optional thumbnails.
- Optional automatic rotation with interval, loop and explicit pause/resume; interaction/focus stops rotation until resumed, hover suspends it.
- Resizing retains the selected page. Offscreen/background, native screen reader and reduced motion suspend automatic rotation.
Accessibility
- Named 44pt previous/next and page controls provide alternatives to swiping.
- messages.page translates every page label; large collections use a count.
- Page content retains its own interactive descendants.
Motion
- Uses the
selectmotion role, so it follows your app's feel. Passmotionto tune this one instance. - Paging is native scrolling; dots use the select role.
- Reduce Motion jumps between pages when you tap a dot.
- Reduced motion disables automatic rotation; focus and manual interaction stop it until explicit resume.
Performance
- Pages are virtualised with FlatList, so long galleries stay light.
Notes for AI
- Give pages unique ids; pass index with onIndexChange to control it.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.