Install react-native-ratings
masterInstall the package using either yarn or npm:
yarn add react-native-ratings
# OR
npm install --save react-native-ratingsrepository·master·Indexed 21 days ago
https://github.com/monte9/react-native-ratingsA React Native component library for interactive rating interfaces. It includes the Rating component for swipe-based interactions with support for star, rocket, bell, heart, or custom icons, and the AirbnbRating component for tap-based interactions featuring customizable text labels for reviews.
Install the package using either yarn or npm:
yarn add react-native-ratings
# OR
npm install --save react-native-ratingsThe AirbnbRating component provides a rating interface similar to Airbnb, featuring text labels (reviews) that appear when a user taps a specific rating value. It supports custom colors for the icons, text, and background, as well as custom review labels.
Key features:
reviews: An array of strings used as labels for each rating level.count: Total number of ratings to display.onFinishRating: Callback function that returns the final rating value as a whole number.import { AirbnbRating } from 'react-native-ratings';
<AirbnbRating
count={11}
reviews={["Terrible", "Bad", "Meh", "OK", "Good", "Hmm...", "Very Good", "Wow", "Amazing", "Unbelievable", "Jesus"]}
defaultRating={11}
size={20}
/>The Rating component is a versatile component that supports various built-in icon types (star, rocket, bell, heart) or a custom type using your own image. It supports both tap and swipe interactions.
Key features:
type: Choose from star, rocket, bell, heart, or custom.ratingImage: Used when type='custom' to provide a custom image source.onFinishRating: Callback function triggered when the user completes the rating.jumpValue: If set (e.g., 0.5), the rating increments in steps of that value instead of whole numbers.import { Rating } from 'react-native-ratings';
// Standard star rating
<Rating
showRating
onFinishRating={this.ratingCompleted}
style={{ paddingVertical: 10 }}
/>
// Heart type rating
<Rating
type='heart'
ratingCount={3}
imageSize={60}
showRating
onFinishRating={this.ratingCompleted}
/>
// Custom image rating
const WATER_IMAGE = require('./water.png')
<Rating
type='custom'
ratingImage={WATER_IMAGE}
ratingColor='#3498db'
ratingBackgroundColor='#c8c7c8'
ratingCount={10}
imageSize={30}
onFinishRating={this.ratingCompleted}
style={{ paddingVertical: 10 }}
/>The Rating component accepts the following props (defined by RatingProps):
| prop | default | type | description |
|---|---|---|---|
type | star | string | Built-in types: star, rocket, bell, heart or custom for custom images |
ratingImage | star | string | Custom image source (used with type='custom') |
ratingColor | #f1c40f | string (color) | Custom fill-color for the rating icon (used with type='custom') |
ratingBackgroundColor | white | string (color) | Custom background-fill-color for the rating icon (used with type='custom') |
tintColor | none | string | Color used to change the background of the rating icon |
ratingCount | 5 | number | Number of rating images to display |
ratingTextColor | none | string | Color used for the text labels |
imageSize | 50 | number | Size of each rating image |
showRating | none | boolean | Displays the Built-in Rating UI to show the rating value in real-time |
readonly | false | boolean | Whether the rating can be modified by the user |
startingValue | ratingCount/2 | number | Initial rating to render |
fractions | 2 | number | Decimal places for the rating value (0 to 20) |
minValue | 0 | number | Minimum value the user can select |
style | none | style | Additional styling for the container view |
jumpValue | 0 | number | Value to jump when rating changes (e.g., 0.5 allows increments like 0, 0.5, 1.0...) |
onStartRating | none | function(rating: number) | Callback when the user starts rating |
onSwipeRating | none | function(rating: number) | Callback when the user is swiping |
onFinishRating | none | function(rating: number) | Callback when the user finishes rating (required) |
The TapRating component accepts the following props for customization:
| Prop | Type | Default | Description |
|---|---|---|---|
count | number | 5 | Total number of ratings to display. |
reviews | string[] | ['Terrible', 'Bad', 'Okay', 'Good', 'Great'] | Labels to show when each value is tapped (e.g., index 0 is used if the first star is tapped). |
showRating | boolean | true | Determines if the review text label is shown above the stars. |
reviewColor | string | #f1c40f | Color value for the review text. |
reviewSize | number | 40 | Font size for the review text. |
defaultRating | number | 3 | Initial value for the rating. |
starContainerStyle | StyleProp<ViewStyle> | undefined | Style for the container holding the stars. |
ratingContainerStyle | StyleProp<ViewStyle> | undefined | Style for the overall rating container. |
onFinishRating | (number) => void | undefined | Callback triggered when the user finishes rating. Receives the final rating as a whole number. |
isDisabled | boolean | false | Whether the rating can be modified by the user. |
selectedColor | string | #004666 | Color value for filled stars. |
unSelectedColor | string | #BDC3C7 | Color value for unfilled stars. |
size | number | 40 | Size of the rating image/star. |
starImage | string | undefined | Custom base image source for the stars. |
starStyle | StyleProp<ViewStyle> | undefined | Style for individual stars. |
The AirbnbRating component accepts the following props:
| prop | default | type | description |
|---|---|---|---|
defaultRating | 3 | number | Initial value for the rating |
reviews | ['Terrible', 'Bad', 'Okay', 'Good', 'Great'] | string[] | Labels to show when each value is tapped (index 0 corresponds to the first star) |
count | 5 | number | Total number of ratings to display |
selectedColor | #f1c40f | string (color) | Custom fill-color for the rating icon |
unSelectedColor | #BDC3C7 | string (color) | Custom not fill-color for the rating icon |
reviewColor | #f1c40f | string (color) | Custom text color for the review text |
size | 40 | number | The size of each rating image (optional) |
reviewSize | 25 | number | Custom font size for the review text |
showRating | true | boolean | Determines if to show the reviews above the rating |
isDisabled | false | boolean | Whether the rating can be modified by the user |
onFinishRating | none | function(value: number) | Callback method when the user finishes rating. Returns the final rating value as a whole number |
starContainerStyle | none | object or stylesheet | Custom styles applied to the star container |
ratingContainerStyle | none | object or stylesheet | Custom styles applied to the rating container |
starImage | STAR_IMAGE | string | Custom base image source (optional) |
starStyle | none | object or stylesheet | Custom styles applied to the star (optional) |
To use a custom image instead of the built-in star, heart, rocket, or bell, set the type prop to 'custom' and provide a ratingImage source. You can also specify custom ratingColor and ratingBackgroundColor to match your design.
import { Image } from 'react-native';
import SwipeRating from 'react-native-ratings/src/SwipeRating';
const MyCustomIcon = () => (
<Image source={require('./my-icon.png')} />
);
<SwipeRating
type="custom"
ratingImage={<MyCustomIcon />}
ratingColor="#3498db"
ratingBackgroundColor="#ecf0f1"
/>The SwipeRating component allows users to provide a rating by swiping across a set of icons. It supports built-in icon types (star, heart, rocket, bell) or custom images. You can configure the number of icons, their size, colors, and handle rating events via callbacks.
import SwipeRating from 'react-native-ratings/src/SwipeRating';
<SwipeRating
type="star"
ratingCount={5}
imageSize={40}
onFinishRating={(rating) => console.log(rating)}
/>The SwipeRating component accepts the following props to customize its behavior and appearance:
type: The icon type to use. Options: 'star', 'heart', 'rocket', 'bell', or 'custom'. (Default: 'star')ratingImage: A custom image source. Required if type='custom'.ratingColor: Custom fill color for the icon. (Default: '#f1c40f')ratingBackgroundColor: Custom background fill color for the icon. (Default: 'white')ratingCount: Total number of icons to display. (Default: 5)imageSize: The size of each rating icon in pixels. (Default: 40)tintColor: Color applied to the icon image via tintColor.ratingTextColor: Color used for the real-time rating text labels. (Default: matches type color)style: A ViewStyle object for the container view.startingValue: The initial rating value to render. (Default: ratingCount / 2)minValue: The minimum selectable rating value. (Default: 0)fractions: Number of decimal places for the rating value. Must be a number between 0 and 20.jumpValue: The number to jump per swipe. If set, the rating will snap to increments. (Default: 0)readonly: If true, the user cannot modify the rating. (Default: false)onStartRating: Called when the user begins the rating gesture.onSwipeRating: Called continuously as the user swipes. Receives the current rating value.onFinishRating: Called when the user finishes the gesture. Receives the final rating value as a whole number (unless fractions is used).showRating: Whether to display the real-time rating value UI (e.g., "Rating: 3/5"). (Default: false)showReadOnlyText: Whether to show a "(readonly)" label when readonly is true. (Default: false)The TapRating component provides an interactive star rating interface where users can tap stars to select a rating. It can display text labels (reviews) corresponding to each rating level and supports customization of colors, sizes, and styles.
import TapRating from 'react-native-ratings/TapRating';
<TapRating
count={5}
defaultRating={3}
reviews={['Terrible', 'Bad', 'Okay', 'Good', 'Great']}
onFinishRating={(rating) => console.log('User rated:', rating)}
/>The react-native-ratings package provides two primary rating components: Rating (for swipe-based interaction) and AirbnbRating (for tap-based interaction). You can import them from the root package entrypoint.
import { Rating, AirbnbRating } from 'react-native-ratings';To type your component props when using the tap-based AirbnbRating component, import the TapRatingProps type.
import type { TapRatingProps } from 'react-native-ratings';