An interactive rating component for React Native, which can display ratings using stars, hearts, emojis, or custom symbols of your choice. The component leverages the PanResponder
and Animated
APIs to create high-performing animations. It is written in TypeScript and has zero dependencies. Whether you’re building a review-based app, a rating system, or any application that requires user feedback, React Native Rating will be an invaluable addition to your toolkit.
![](https://private-user-images.githubusercontent.com/4656448/239993348-0a17986a-5846-41d3-99d9-9e687198a078.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMzU1NTYsIm5iZiI6MTcyNDAzNTI1NiwicGF0aCI6Ii80NjU2NDQ4LzIzOTk5MzM0OC0wYTE3OTg2YS01ODQ2LTQxZDMtOTlkOS05ZTY4NzE5OGEwNzguZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTlUMDI0MDU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmI2ZDU0MWNhNGVhNDY0ZDU5M2Y0NzNhMjg2Y2ExNzI5MzE5MTRmODFhY2E4MzYxMzdmMzNjZWIzNmExZjIxNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.t4fOWNJce79VqgJf-3BSmf0Q-atfMnhG8Aosu1ffiys)
yarn add @kolking/react-native-rating
npm i @kolking/react-native-rating
import React, { useCallback, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Rating } from '@kolking/react-native-rating';
const App = () => {
const [rating, setRating] = useState(0);
const handleChange = useCallback(
(value: number) => setRating(Math.round((rating + value) * 5) / 10),
[rating],
);
return (
<View style={styles.root}>
<Rating size={40} rating={rating} onChange={handleChange} />
<Text style={styles.text}>Rated {rating} out of 5</Text>
</View>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 17,
marginTop: 20,
},
});
export default App;
Prop | Type | Default | Description |
---|---|---|---|
variant |
Variants | stars |
Pre-defined design variant, see variants section below |
rating |
number | 0 |
Decimal rating value |
size |
number | 30 |
Width and height of the rating symbol |
scale |
number | 1.3 |
Scaling factor for the snap animation, set it to 1 to turn animation off |
spacing |
number | size * (scale - 1) |
Distance between symbols, calculated based on the scale prop if no value is provided |
maxRating |
number | 5 |
Maximum rating value and the total number of symbols |
disabled |
boolean | false |
Set true to disable user interaction |
baseColor |
string | variant default | Color of the "empty" symbols |
fillColor |
string | variant default | Color of the "filled" symbols |
touchColor |
string | variant default | Color of the symbols during interaction |
baseSymbol |
SymbolSource | variant default | An image (or array of images) for the "empty" rating |
fillSymbol |
SymbolSource | variant default | An image (or array of images) for the "filled" rating |
style |
ViewStyle | Style object applied to the wrapping View | |
onMove |
(rating: number) => void |
A function called during pan gesture | |
onChange |
(rating: number) => void |
A function called when touch released |
When rendering a lot of rating components on the same screen, e.g. in a FlatList
or SectionList
, make sure to set the disabled
prop to true
. Otherwise you may encounter the "excessive number of pending callbacks" warning.
To achieve a customized appearance for the component, you have the flexibility to define your own symbols using the baseSymbol
and fillSymbol
props. The SymbolSource
type is defined as ImageSourcePropType | ImageSourcePropType[]
, allowing you to pass either a single image source or an array of images. It is important to note that when passing an array, its length must match the maxRating
value to ensure proper functionality.
There are five pre-defined design variants available for selection. All of the variants are designed to support both light and dark color schemes. In addition, you have the flexibility to override any of the variant props with your own custom values.
Preview | baseSymbol |
fillSymbol |
baseColor |
fillColor |
touchColor |
---|---|---|---|---|---|
#D1D1D6 light#3A3A3C dark |
#FF9500 light#FF9F0A dark |
#FF3B30 light#FF453A dark |
Preview | baseSymbol |
fillSymbol |
baseColor |
fillColor |
touchColor |
---|---|---|---|---|---|
#C7C7CC light#48484A dark |
#FF9500 light#FF9F0A dark |
#FF3B30 light#FF453A dark |
Preview | baseSymbol |
fillSymbol |
baseColor |
fillColor |
touchColor |
---|---|---|---|---|---|
#D1D1D6 light#3A3A3C dark |
#FF2D55 light#FF375F dark |
#D70015 light#D70015 dark |
Preview | baseSymbol |
fillSymbol |
baseColor |
fillColor |
touchColor |
---|---|---|---|---|---|
#C7C7CC light#48484A dark |
#FF2D55 light#FF375F dark |
#D70015 light#D70015 dark |
Preview | baseSymbol |
---|---|
I appreciate your feedback, so please star the repository if you like it. This is the best motivation for me to maintain the package and add new features. If you have any feature requests, found a bug, or have ideas for improvement, feel free to open an issue.
Licensed under the MIT license.