Package-level declarations

Rating components display or collect a 1-5 star score. Use display variants to show existing scores and RatingInput to let users submit their own.

Variants

VariantPurposeAccepts fractional values
RatingDisplayRaw star row, no labelYes (Float 0–5)
RatingFullStars with numeric value, label, and review countYes (Float 0–5)
RatingSimpleSingle star + numeric value + optional review countYes (Float 1–5)
RatingSimpleLargeLarge single-star display, no review countYes (Float 1–5)
RatingInputInteractive 5-star pickerNo (Int 0–5)
RatingStarAtomic star icon (full, half, empty)Via RatingStarState

RatingDisplay

A row of five stars reflecting a fractional value. Values below 0.5 render nothing.

RatingDisplay(value = 3.5f)

Pass size to override the default 12dp star size:

RatingDisplay(
value = 4.2f,
size = RatingDefault.StarSize, // 16dp
)

RatingFull

Displays 3,4 ★★★☆☆ Label (5 avis) — numeric value, stars, optional label, and optional review count. Requires a value in the range [1..5]; values outside this range render nothing.

RatingFull(
value = 3.6f,
commentCount = 42,
)

Pass label to append a category name after the stars:

RatingFull(
value = 4.2f,
label = "Communication",
commentCount = 5,
)

Pass locale = null to hide the numeric prefix:

RatingFull(
value = 3.6f,
commentCount = 23,
locale = null,
)

RatingSimple

A compact single-star summary — ★ 3,4 (5). Annotated @ExperimentalSparkApi.

RatingSimple(
value = 4.5f,
commentCount = 12,
)

Control which side the numeric label appears on with labelSide:

RatingSimple(
value = 4.5f,
labelSide = RatingLabelSide.Start, // "4,5 ★"
)

RatingSimpleLarge

An oversized version of RatingSimple — renders the value in display3 typography with a /5 suffix, no review count. Annotated @ExperimentalSparkApi.

RatingSimpleLarge(
value = 4.5f,
locale = Locale.US,
)

RatingInput

An interactive 5-star picker. Accepts tap and horizontal drag gestures, triggers haptic feedback on drag, and exposes semantics as a slider for accessibility services (TalkBack, Switch Access). Keyboard navigation uses Shift + Arrow keys to increment or decrement.

var rating by remember { mutableIntStateOf(0) }

RatingInput(
value = rating,
onRatingChanged = { rating = it },
)

Disable the picker while a submission is in flight:

RatingInput(
value = rating,
onRatingChanged = { rating = it },
enabled = false,
)

Supply a custom accessibility description when the default "N stars" wording does not fit the context:

RatingInput(
value = rating,
onRatingChanged = { rating = it },
stateDescription = { value -> "$value out of 5" },
)

Set allowSemantics = false when embedding RatingInput inside a parent that declares its own semantics, to prevent duplicate TalkBack announcements:

RatingInput(
value = rating,
onRatingChanged = { rating = it },
allowSemantics = false,
)

RatingStar

The atomic star icon. Use it when none of the composite components match your layout needs.

RatingStarState accepts a Boolean, Int (0 or 1), Float (0.0–1.0), or Double:

RatingStar(state = RatingStarState.Full)
RatingStar(state = RatingStarState.Half)
RatingStar(state = RatingStarState.Empty)

// Derived from a Float — 0.0–0.25 → Empty, 0.25–0.75 → Half, 0.75–1.0 → Full
RatingStar(state = RatingStarState(0.6f))

Pass enabled = false to render the star at reduced opacity:

RatingStar(
state = RatingStarState.Full,
enabled = false,
size = RatingDefault.StarSize,
)

Sizing

ConstantValueUsed by
RatingDefault.SmallStarSize12dpRatingDisplay, RatingSimple
RatingDefault.StarSize16dpRatingFull, RatingStar
RatingDefaults.StarSize40dpRatingInput touch target interior

Accessibility

  • RatingFull and RatingSimple merge all descendants into a single node with a locale-aware content description ("3.6 stars" or "3.6 stars, 42 reviews").

  • RatingInput exposes a ProgressBarRangeInfo so TalkBack announces it as a slider. Swipe up/down adjusts the value in increments of one. Shift + Arrow provides the same control from a keyboard.

  • Individual RatingStar instances carry no content description; they rely on a parent node to supply context.

Types

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Enum that represents possible star states.

Functions

Link copied to clipboard
fun RatingDisplay(@FloatRange(from = 0.0, to = 5.0) value: Float, modifier: Modifier = Modifier, size: Dp = RatingDefault.SmallStarSize)

A display for a rating value.

Link copied to clipboard
fun RatingFull(@FloatRange(from = 0.0, to = 5.0) value: Float, modifier: Modifier = Modifier, commentCount: Int? = null, label: String? = null, locale: Locale? = firstLocale())

Display the value rating of an user with stars optionally followed by a label and/or commentCount in the following form 3,4 ★★★☆☆ Communication (5)

Link copied to clipboard
fun RatingInput(@IntRange(from = 0, to = 5) value: Int, onRatingChanged: (Int) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, stateDescription: (Int) -> String = { "$it stars" }, allowSemantics: Boolean = true, testTag: String? = null)

A rating input component that allows the user to select a rating from 0 to 5. This component can have it's value changed either by a tap on the star or dragging horizontally.

Link copied to clipboard
fun RatingSimple(@FloatRange(from = 0.0, to = 5.0) value: Float, modifier: Modifier = Modifier, commentCount: Int? = null, locale: Locale = firstLocale(), labelSide: RatingLabelSide = RatingDefault.LabelSide)

Component that displays a compressed version of user rating

Link copied to clipboard
fun RatingSimpleLarge(@FloatRange(from = 0.0, to = 5.0) value: Float, modifier: Modifier = Modifier, locale: Locale = firstLocale(), labelSide: RatingLabelSide = RatingDefault.LabelSide)

This function displays a large simple version of user rating.

Link copied to clipboard
fun RatingStar(modifier: Modifier = Modifier, size: Dp = RatingDefault.SmallStarSize, state: RatingStarState = RatingStarState(1), enabled: Boolean = true)

RatingStar is the atomic element of rating components

Link copied to clipboard

Return corresponding RatingStarState based on a Boolean representation

fun RatingStarState(@FloatRange(from = 0.0, to = 1.0) starValue: Double): RatingStarState

Return corresponding RatingStarState based on a Double representation

fun RatingStarState(@FloatRange(from = 0.0, to = 1.0) starValue: Float): RatingStarState

Return corresponding RatingStarState based on a Float representation

fun RatingStarState(@IntRange(from = 0, to = 1) starValue: Int): RatingStarState

Return corresponding RatingStarState based on a Int representation