Home

Awesome

<h1 align="center"> React Native Rating Element </h1>

A simple rating library for react native supporting:

<h3 align="center"> <a href="https://github.com/ui-ninja/react-native-rating-element#installation">Installation</a> <span> · </span> <a href="https://github.com/ui-ninja/react-native-rating-element#usage">Usage</a> <span> · </span> <a href="https://github.com/ui-ninja/react-native-rating-element#api">API Documentation</a> <span> · </span> <a href="https://github.com/ui-ninja/react-native-rating-element#output">Sample Output</a> <span> · </span> </h3> <div align="center"> <img src="https://s7.gifyu.com/images/ratingV5.1.3.gif" width="200" /> </div>

Please note: This package depends on react-native-vector-icons. Please configure it for iOS and android before using this package. <br /> - For iOS, you will need to add Ionicons.ttf file from node_modules/react-native-vector-icons to Fonts folder and then edit Info.plist. Try this article <br /> - For android - Please follow these instruction.

Installation

Use the package manager npm to install react-native-rating-element.

npm install react-native-rating-element

Usage

import { Rating } from "react-native-rating-element";

<Rating
  rated={3.7}
  totalCount={5}
  ratingColor="#f1c644"
  ratingBackgroundColor="#d4d4d4"
  size={24}
  readonly // by default is false
  icon="ios-star"
  direction="row" // anyOf["row" (default), "row-reverse", "column", "column-reverse"]
/>

**Custom Image, onIconTap and bottom to top direction**
<Rating
  rated={3.7}
  totalCount={5}
  size={42}
  onIconTap={position => console.log(`User pressed: ${position}`)}
  direction="column-reverse"
  type="custom" // default is always to "icon"
  selectedIconImage={require('./filled.png')}
  emptyIconImage={require('./empty.png')}
/>

API

propdefaulttypedescription
rated0numberRepresents Initial value for the rating.
totalCount5numberNumber of background stars to show. For ex. Rated 5 out of 10 stars. The 10 value is totalCount
typeiconstringIf you want custom images, then pass custom as prop value. <br />In case of custom, Make sure to pass selectedIconImage and emptyIconImage.
selectedIconImage-image path (node)Pass in custom path for selected icon. For ex. selectedIconImage={require('../pathToImage/image.png}.
emptyIconImage-image path (node)Pass in custom path for selected icon. For ex. emptyIconImage={require('../pathToImage/image.png}.
readonlyfalseboolIf passed true, onIconTap event won't be fired.
direction'row'stringPass any value from [ "row", "row-reverse", "column", "column-reverse"].
onIconTap-funcOn press of star icon by user, this function will be invoked with position paramter. For ex. when user taps on 4 rating, this function will be invoked and in position parameter you will get value 4. Please note: This won't be triggered if readonly is passed as true.
ratingColor#f1c644string (color)Pass in a custom color to fill-color the rating icon.
ratingBackgroundColor#d4d4d4string (color)Pass in a custom fill-color for the background of rating icon. It is sometimes referred as empty icon.
size24numberPass in a custom font size for the icon
icon'ios-star'stringPass in a custom text for the icon. For ex. 'beer', 'bulb'. These icons are imported from package react-native-vector-icons. Please Note: For now this package only support Ionicons
marginBetweenRatingIcon1numberPass in custom number to manage space or margin between the rating icons.

Output

Output

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT