SwipeUI

Rating

Animated star selection with accessible increment and decrement actions.

npx @swipeui/cli add rating
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Asking people to rate a product, a ride or an experience from one to five stars.
  • Showing a read-only rating with the same stars.
  • Quick feedback prompts after a task.

When not to use it

  • Showing an average with decimals. Use text, such as "4.6 out of 5".
  • Reactions or likes. Use Reactions.
  • Long surveys. Use Radio group.

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 rating
  • Adds components/swipeui/ui/rating-palette.ts, components/swipeui/ui/use-rating.ts, components/swipeui/ui/rating.tsx and 13 shared helpers.
  • Installs uniwind, react-native-gesture-handler, react-native-worklets, react-native-svg, react-native-reanimated, clsx, tailwind-merge, class-variance-authority, expo-haptics. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/review.tsx
import { Rating } from '@/components/swipeui/ui/rating';

<Rating accessibilityLabel="Review rating" defaultValue={3} />;

Examples

Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.

API reference

RatingProps

PropTypeDefaultDescription
value?number—

Controlled score.

defaultValue?number0

Initial score.

onValueChange?((value: number) => void)—

Reports live detents.

onValueCommit?((value: number) => void)—

Reports the final accepted score.

max?number5

Number of glyphs, 1–10.

step?0.5 | 11

Editable detents.

allowClear?booleantrue

Re-tap the selected score to clear.

clearable?boolean—

1.x alias for allowClear.

readOnly?booleanfalse

Display a fractional score without editing.

disabled?booleanfalse

Prevent editing.

showLabel?booleantrue

Show the rolling word label.

labels?readonly string[]—

Labels indexed by rounded score minus one.

size?"lg" | "md" | "sm"'md'

Glyph size, with 44pt targets.

icon?union'star'

Built-in shape or custom glyph renderer.

scrub?booleantrue

Drag across glyphs to scrub.

haptics?boolean | SelectionHapticstrue

Selection feedback.

motion?MotionOverride—

Shared motion override.

accessibilityLabel?string'Rating'

Spoken purpose.

messages?object—

Localized label templates.

className?string—

Root classes.

style?StyleProp<ViewStyle>—

Root style.

testID?string—

Root ID; glyphs append their one-based index.

Native view/input props not listed here pass through where the exported TypeScript type allows them.

Rating settings

PropDoesDefault
hapticsEnables selection or press feedbacktrue
motionOverrides the app's motion feelApp feel

| step | Whole or half detents | 1 | | allowClear | Re-tap the score to clear; clearable is the 1.x alias | true | | readOnly | Show exact fractional averages | false | | showLabel | Rolling score or word label | true | | labels | Word for each score | Score text | | size | sm, md or lg; 44pt targets remain | md | | icon | Drawn star, heart or custom renderer | star | | scrub | Drag through detents | true | | onValueCommit | Final score after release | — |

Composition and behavior

  • max stars (5 by default); value is the current rating.
  • clearable lets a tap on the selected star clear it.

Behavior and gestures

  • Tap a star to set the rating; the stars fill up to it with a selection tick.
  • Tap the selected star again to clear the rating (turn off with clearable={false}).
  • Disabled ratings don't change.

Accessibility

  • The whole control is adjustable and reads like "3 of 5 stars".
  • Swipe up or down with VoiceOver, or use increment and decrement, to change it.
  • Name it with accessibilityLabel, such as "Rate your ride".

Motion

  • Uses the select and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Stars fill with the select role; the tick plays after they settle.
  • Reduce Motion fills them instantly.

Performance

  • Simple pressables; cheap even in lists.

Notes for AI

  • Set max for a different scale; 0 means no rating.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items