Command palette

@yasinsensoy/native

React Native · Components

Rating

Giving and showing a rating with stars (or your own icon).

3 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Click, hover, slide your finger on a phone or try ←/→ and the number keys.

Code

import { RatingField } from "@yasinsensoy/native";

<RatingField label="How did you like this product?" name="puan" step={0.5} showValue size="lg" required
  labels={["Bad", "Okay", "Good", "Very good", "Excellent"]} />

Events

  1. Events appear here when you interact with the preview.

Product card: read only, fractional average and review count

Hearts, out of 10

Satisfaction: a separate face for each score (highlight=single)

😞🙁😐🙂😍

Controlled: write the previewed score yourself

Puan: 3 · Preview: —

Import

import { Rating } from "@yasinsensoy/native";

Rating

component

Giving and showing a rating with stars (or your own icon). The same calculations as Rating on web (@yasinsensoy/core/rating-math).

  • Rate by tapping or sliding the finger over the icons; a label bubble shows while dragging. Vertical scrolling is not blocked.
  • step={0.5} for half points; read-only values like 4.3 are drawn proportionally.
  • With a screen reader swiping up/down changes the score.
Rating(props: RatingProps): JSX.Element

Examples

<Rating defaultValue={4} accessibilityLabel="Product rating" />
<Rating readOnly value={4.3} size="sm" showValue={(v) => `${v} · 128 reviews`} />
<Rating step={0.5} showValue labels={["Bad", "Okay", "Good", "Very good", "Excellent"]} />

Rating icon: a single icon or a function giving an icon per score.

type RatingIcon = IconProp | ((index: number) => IconProp)

RatingProps

interface

Props of Rating.

Extends: FieldProps

NameTypeDefaultDescription
value?numberRating (controlled); 0 if there is no rating.
defaultValue?number0Initial score (uncontrolled).
onValueChange?(value: number) => voidWhen the score changes.
onHoverChange?(value: number | null) => voidScore previewed while the finger moves over the icons; null on release.
max?number5Number of icons (the highest score).
step?number1Score step: 0.5 for half stars. Read-only, any value is drawn proportionally.
icon?RatingIcona starIcon (filled layer); outline icons are painted filled.
emptyIcon?RatingIcona muted version of `iconEmpty icon.
highlight?"range" | "single""range"range fills all up to the score; single only the chosen one (face scales).
labels?readonly ReactNode[]Name of each score ("Bad"… "Excellent"): in the bubble while dragging, and for screen readers.
showValue?boolean | ((value: number, previewing: boolean) => ReactNode)Writes the score next to it: true the number (or label), a function your own text.
clearable?booleantrueTapping the same score again clears it.
tone?Tone"warning"` (a yellow star)Color of filled icons.
size?Size"md"Icon size: 16, 24, 32 pixels.
readOnly?booleanDisplay only; cannot be tapped.
disabled?booleanDisabled.
accessibilityLabel?stringScreen reader label.
effect?EffectPropEffect of the icons ("bounce", "pulse", "glow"…); stays on for the icon under the finger. Defaults to appearance.defaults.rating.effect. See BuiltinEffect.
tooltip?TooltipPropTooltip shown on long press (in read-only display). See TooltipProp.
style?StyleProp<ViewStyle>Container style.