Rating

A star rating input with fractional read-only display, custom icons, sizes, and interactive selection.

Import

import { Rating } from 'heroui-native-pro';

Anatomy

<Rating>
  <Rating.Item value={1} />
  <Rating.Item value={2} />
  <Rating.Item value={3} />
  <Rating.Item value={4} />
  <Rating.Item value={5} />
</Rating>
  • Rating: Root container built on heroui-native's RadioGroup. Manages the numeric value, auto-renders items from 1 to maxValue when children are omitted, and propagates size/icon/read-only state via context.
  • Rating.Item: Individual rating item. Wraps RadioGroup.Item and renders the default icon plus a clipped overlay for partial fills. Supports render-function children for fully custom indicators.

Usage

Basic usage

Auto-renders 5 items and calls onValueChange with the selected integer value.

const [value, setValue] = useState(3);

<Rating value={value} onValueChange={setValue} />;

Uncontrolled

<Rating defaultValue={4} />

Sizes

Control item size with the size prop.

<Rating size="sm" defaultValue={4} />
<Rating size="md" defaultValue={4} />
<Rating size="lg" defaultValue={4} />

Read-only fractional

isReadOnly disables interaction and enables fractional fills (e.g. 3.5, 4.2). The partial fill is achieved by clipping a second copy of the icon, so any solid-fill icon can be used.

<Rating isReadOnly value={4.5} />
<Rating isReadOnly value={3.25} />

Max value

Ratings are not limited to 5 items — set maxValue to render any number of items.

<Rating maxValue={10} defaultValue={7} size="sm" />

Disabled

<Rating isDisabled value={3} />

Custom icon

Pass an icon prop with any SVG component. The component is expected to accept size, color, and colorClassName props so Rating can drive its dimensions and active / inactive colors. Wrap the SVG with withUniwind to enable colorClassName:

import type { FC } from 'react';
import Svg, { Path, type SvgProps } from 'react-native-svg';
import { withUniwind } from 'uniwind';

interface HeartIconProps extends SvgProps {
  size?: number;
  color?: string;
  colorClassName?: string;
}

const HeartIconBase: FC<HeartIconProps> = ({
  size = 24,
  color = 'currentColor',
  ...rest
}) => (
  <Svg width={size} height={size} viewBox="0 0 24 24" fill="none" {...rest}>
    <Path d="M12 21s-7-4.35-9.5-9.2..." fill={color} />
  </Svg>
);

const HeartIcon = withUniwind(HeartIconBase, {
  color: { fromClassName: 'colorClassName', styleProperty: 'accentColor' },
});

<Rating icon={<HeartIcon />} defaultValue={3} />;

Customizing icon size and colors

Use iconProps on the root to override size and active / inactive colors for every item. When both a raw color (activeColor / inactiveColor) and a className (activeColorClassName / inactiveColorClassName) are provided, the className wins for theme-aware styling.

<Rating
  icon={<HeartIcon />}
  iconProps={{
    size: 28,
    activeColorClassName: 'accent-danger',
    inactiveColorClassName: 'accent-muted/20',
  }}
  defaultValue={3}
/>

Custom indicator

Pass a render-function child to Rating.Item for a fully custom indicator. The function receives { isActive, isPartial, partialPercent }.

<Rating>
  {[1, 2, 3, 4, 5].map((itemValue) => (
    <Rating.Item key={itemValue} value={itemValue}>
      {({ isActive, partialPercent }) => (
        <View className="size-9 rounded-full items-center justify-center bg-muted/10">
          <Text className={isActive ? 'text-warning' : 'text-muted'}>
            {partialPercent > 0 && partialPercent < 100
              ? `${(itemValue - 1 + partialPercent / 100).toFixed(1)}`
              : itemValue}
          </Text>
        </View>
      )}
    </Rating.Item>
  ))}
</Rating>

Example

import { Rating } from 'heroui-native-pro';
import { Text, View } from 'react-native';
import { useState } from 'react';

export default function RatingExample() {
  const [value, setValue] = useState(4);

  return (
    <View className="items-center gap-2">
      <Rating value={value} onValueChange={setValue} />
      <Text className="text-muted text-sm">Rating: {value}</Text>
    </View>
  );
}

API Reference

Rating

proptypedefaultdescription
valuenumber-Controlled rating value (integer; fractional only when isReadOnly)
defaultValuenumber-Uncontrolled default rating value
onValueChange(value: number) => void-Callback fired when the selected rating changes. Always receives an integer
maxValuenumber5Maximum rating value. Controls the number of items auto-rendered when children is absent
size'sm' | 'md' | 'lg''md'Size of the rating items
isReadOnlybooleanfalseDisables interaction and enables fractional value for partial fills
isDisabledbooleanfalseDisables the rating entirely (opacity + no interaction)
iconReactNode-Custom icon element used by every item (item-level icon wins). Must accept size, color, and colorClassName props
iconPropsRatingIconProps-Shared icon styling (size + active / inactive colors) applied to every item
classNamestring-Additional CSS classes applied to the root

Extends heroui-native RadioGroup except for value, defaultValue, onValueChange, and children which are overridden to accept numeric ratings.

RatingIconProps

Shared icon styling forwarded to the default star or any custom icon component. When both a raw color and a className are set, the className wins — the raw color is used as a fallback.

proptypedefaultdescription
sizenumberDerived from root sizeIcon size in pixels
activeColorstring-Raw fill color for active / partially active items
inactiveColorstring-Raw fill color for inactive items
activeColorClassNamestring'accent-warning'Uniwind colorClassName for active / partially active items
inactiveColorClassNamestring'accent-surface-tertiary'Uniwind colorClassName for inactive items

Rating.Item

The underlying pressable is an animated RadioGroup.Item that plays a subtle scale animation on press. Customize or disable it via the animation prop (or disable animated styles entirely with isAnimatedStyleActive={false}).

proptypedefaultdescription
valuenumber-1-based numeric value of this item
iconReactNode-Custom icon for this specific item (overrides the root-level icon)
childrenReactNode | ((p: RatingItemRenderProps) => Node)-Content or render function for a fully custom indicator
animationRatingItemAnimation-Animation configuration for the press-scale feedback. Pass false or 'disabled' to disable
isAnimatedStyleActivebooleantrueWhether the animated press-scale style is applied. Set to false to disable animated styles and apply your own
classNamestring-Additional CSS classes applied to the item pressable

Extends heroui-native RadioGroup.Item except for value and children which are overridden.

RatingItemRenderProps

proptypedescription
isActivebooleanWhether the item is considered active (filled or partially filled)
isPartialbooleanWhether the item is partially filled (read-only mode only)
partialPercentnumberPartial fill percentage in the 0-100 range

RatingItemAnimation

Animation configuration for the item press-scale feedback. Can be:

  • false or 'disabled': Disable the item press animation
  • undefined: Use default animation
  • object: Custom animation configuration
proptypedefaultdescription
scale.value[number, number][1, 0.9]Scale values [unpressed, pressed]
scale.timingConfigWithTimingConfig{ duration: 150 }Animation timing configuration

Hooks

useRating

Hook to access the Rating context. Must be used within a Rating component.

import { useRating } from 'heroui-native-pro';

const { value, maxValue, size, isReadOnly, isDisabled, iconProps } =
  useRating();

Returns

propertytypedescription
valuenumberCurrent rating value (may be fractional in read-only mode)
maxValuenumberCurrent maximum rating value
sizeRatingSizeCurrent size
isReadOnlybooleanWhether the rating is read-only
isDisabledbooleanWhether the rating is disabled
iconReactNodeShared default icon (may be undefined)
iconPropsRatingIconPropsShared icon styling (may be undefined)

On this page