Rating
Animated star selection with accessible increment and decrement actions.
npx @swipeui/cli add ratingWhen 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.tsxand 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 installso versions match your SDK.
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
value? | | — | Controlled score. |
defaultValue? | | | Initial score. |
onValueChange? | | — | Reports live detents. |
onValueCommit? | | — | Reports the final accepted score. |
max? | | | Number of glyphs, 1–10. |
step? | | | Editable detents. |
allowClear? | | | Re-tap the selected score to clear. |
clearable? | | — | 1.x alias for allowClear. |
readOnly? | | | Display a fractional score without editing. |
disabled? | | | Prevent editing. |
showLabel? | | | Show the rolling word label. |
labels? | | — | Labels indexed by rounded score minus one. |
size? | | | Glyph size, with 44pt targets. |
icon? | | | Built-in shape or custom glyph renderer. |
scrub? | | | Drag across glyphs to scrub. |
haptics? | | | Selection feedback. |
motion? | | — | Shared motion override. |
accessibilityLabel? | | | Spoken purpose. |
messages? | | — | Localized label templates. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | 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
| Prop | Does | Default |
|---|---|---|
| haptics | Enables selection or press feedback | true |
| motion | Overrides the app's motion feel | App 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
selectandpressmotion roles, so it follows your app's feel. Passmotionto 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 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.