suiss/uim · React Native Component

Carousel

A swipeable row or column of slides with arrow buttons, dots and optional autoplay.

Carousel is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Carousel on iOS in light mode

Carousel wraps a scroll view that snaps to each CarouselItem. It scrolls horizontally by default or vertically with orientation="vertical". CarouselPrevious and CarouselNext are round Buttons that sit outside the slides, or inline when placed in CarouselControls.

CarouselDots shows one dot per snap point, with the active dot stretched into a pill; with autoplay on, the active dot fills up as a timer. CarouselPlayButton pauses and resumes autoplay.

Installation

$ pnpm dlx @esuiss/uim@latest add carousel

The CLI also adds what it builds on: Button, Icon.

Manual

  1. Install the dependencies:
npx expo install cn phosphor-react-native react-native-reanimated react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, and the primitives components/primitives/carousel.tsx, components/primitives/use-render.tsx.

  2. Copy the source into components/ui/carousel.tsx:

uniwind/components/ui/carousel.tsx
import { cn } from "cn"
import {
  CaretLeftIcon,
  CaretRightIcon,
  PauseIcon,
  PlayIcon,
} from "phosphor-react-native"
import * as React from "react"
import { I18nManager, View, type ViewProps } from "react-native"
import {
  cancelAnimation,
  Easing,
  ReduceMotion,
  useAnimatedStyle,
  useSharedValue,
  withTiming,
  1. Update the import paths to match your project.

Usage

import { Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext, CarouselControls, CarouselDots, CarouselPlayButton } from "@/components/ui/carousel"
<View className="mx-12">
  <Carousel>
    <NumberSlides />
    <CarouselPrevious />
    <CarouselNext />
  </Carousel>
</View>

Set each slide's width with basis on CarouselItem, as a fraction of the viewport (for example 0.5 for two per view). Use opts for loop, align (start or center) and dragFree scrolling without snapping.

Pass autoplay as true for the default 5-second delay, or as a number of milliseconds. Put CarouselDots, CarouselPlayButton and nav buttons inside CarouselControls to show them in a row below the slides; CarouselDots takes variant="plain" to drop its background.

Use setApi to get a CarouselApi for scrolling from outside, or call useCarousel() inside the carousel to read the selected index and scroll state.

Examples

Multiple items

Two slides per view with basis={0.5}.

iOS
Carousel (multiple items) on iOS in light mode

Loop

Wraps around from the last slide to the first.

iOS
Carousel (loop) on iOS in light mode

Vertical

A vertical carousel with arrows above and below.

iOS
Carousel (vertical) on iOS in light mode

With page indicator

Full-width cards with a page indicator below.

iOS
Carousel (with page indicator) on iOS in light mode

Peeking cards with plain dots and a play button.

iOS
Carousel (featured) on iOS in light mode

Spotlight

A looping showcase with dots and an inline next button.

iOS
Carousel (spotlight) on iOS in light mode

Autoplay

Advances every four seconds, with progress dots and a play button.

iOS
Carousel (autoplay) on iOS in light mode

Shelf

A free-scrolling shelf of small cards with dragFree.

iOS
Carousel (shelf) on iOS in light mode

API Reference

Root that holds the scroll state and options.

ExtendsReact.ComponentProps<typeof CarouselPrimitive.Root>

CarouselContent

Scrolling track for the slides.

ExtendsReact.ComponentProps<typeof CarouselPrimitive.Content>

CarouselItem

One slide.

ExtendsReact.ComponentProps<typeof CarouselPrimitive.Item>

CarouselPrevious

Button that scrolls to the previous slide.

ExtendsReact.ComponentProps<typeof Button>

CarouselNext

Button that scrolls to the next slide.

ExtendsReact.ComponentProps<typeof Button>

CarouselControls

Row that lays out dots and buttons below the slides.

ExtendsViewProps

CarouselDots

One pressable dot per snap point.

ExtendsViewProps
PropType
About
default (on a control background) or plain.
Type
"default""plain"
Default
"default"

CarouselPlayButton

Toggles autoplay.

ExtendsReact.ComponentProps<typeof Button>

Accessibility

  • Previous and next buttons have the button role and are labelled "Previous slide" and "Next slide", with a disabled state at the ends.
  • Each dot is labelled "Go to slide N" and marks the current slide as selected.
  • The play button is labelled "Pause slideshow" or "Play slideshow".

Notes

  • Arrow icons are mirrored in right-to-left layouts.
  • Dot and progress animations respect the system Reduce Motion setting.
  • Uses bg-control, bg-label and bg-label-tertiary tokens; light and dark follow the system appearance.