8.1.0 • Published 3 years ago

react-native-ratings v8.1.0

Weekly downloads
85,230
License
MIT
Repository
github
Last release
3 years ago

Demo - try it now

Demo gif

Tap Rating

Swipe Rating

Installation

Install the package using yarn or npm:

yarn add react-native-ratings

OR

npm install --save react-native-ratings

Usage

import { Rating, AirbnbRating } from 'react-native-ratings';

const WATER_IMAGE = require('./water.png')

ratingCompleted(rating) {
  console.log("Rating is: " + rating)
}

<AirbnbRating />

<AirbnbRating
  count={11}
  reviews={["Terrible", "Bad", "Meh", "OK", "Good", "Hmm...", "Very Good", "Wow", "Amazing", "Unbelievable", "Jesus"]}
  defaultRating={11}
  size={20}
/>

<Rating
  showRating
  onFinishRating={this.ratingCompleted}
  style={{ paddingVertical: 10 }}
/>

<Rating
  type='heart'
  ratingCount={3}
  imageSize={60}
  showRating
  onFinishRating={this.ratingCompleted}
/>

<Rating
  type='custom'
  ratingImage={WATER_IMAGE}
  ratingColor='#3498db'
  ratingBackgroundColor='#c8c7c8'
  ratingCount={10}
  imageSize={30}
  onFinishRating={this.ratingCompleted}
  style={{ paddingVertical: 10 }}
/>

Also refer to the example app for more detailed usage example.

API

AirbnbRating

propdefaulttypedescription
defaultRating3numberInitial value for the rating
reviews'Terrible', 'Bad', 'Okay', 'Good', 'Great'string[]Labels to show when each value is tapped e.g. If the first star is tapped, then value in index 0 will be used as the label
count5numberTotal number of ratings to display
selectedColor#f1c40fstring (color)Pass in a custom fill-color for the rating icon
unSelectedColor#BDC3C7string (color)Pass in a custom not fill-color for the rating icon
reviewColor#f1c40fstring (color)Pass in a custom text color for the review text
size40numberThe size of each rating image (optional)
reviewSize25numberPass in a custom font size for the review text
showRatingtruebooleanDetermines if to show the reviews above the rating
isDisabledfalsebooleanWhether the rating can be modiefied by the user
onFinishRatingnonefunction(value: number)Callback method when the user finishes rating. Gives you the final rating value as a whole number
starContainerStylenoneobject or stylesheetCustom styles applied to the star container
ratingContainerStylenoneobject or stylesheetCustom styles applied to the rating container
starImageSTAR_IMAGEstringPass in a custom base image source (optional)

RatingProps

propdefaulttypedescription
typestarstringChoose one of the built-in types: star, rocket, bell, heart or use type custom to render a custom image (optional)
ratingImagestarstringPass in a custom image source; use this along with type='custom' prop above (optional)
ratingColor#f1c40fstring (color)Pass in a custom fill-color for the rating icon; use this along with type='custom' prop above (optional)
ratingBackgroundColorwhitestring (color)Pass in a custom background-fill-color for the rating icon; use this along with type='custom' prop above (optional)
tintColornonestringColor used to change the background of the rating icon (optional)
ratingCount5numberThe number of rating images to display (optional)
ratingTextColornonestringColor used for the text labels
imageSize50numberThe size of each rating image (optional)
showRatingnonebooleanDisplays the Built-in Rating UI to show the rating value in real-time (optional)
readonlyfalsebooleanWhether the rating can be modiefied by the user
startingValueratingCount/2numberThe initial rating to render
fractions2numberThe number of decimal places for the rating value; must be between 0 and 20
minValue0numberThe minimum value the user can select
stylenonestyleExposes style prop to add additonal styling to the container view (optional)
jumpValue0numberThe value to jump when rating value changes (if jumpValue === 0.5, rating value increases/decreases like 0, 0.5, 1.0, 1.5 ...). Default is 0 (not to jump)
onStartRatingnonefunction(rating: number)Callback method when the user starts rating. Gives you the start rating value as a whole number
onSwipeRatingnonefunction(rating: number)Callback method when the user is swiping. Gives you the current rating value as a whole number
onFinishRatingnonefunction(rating: number)Callback method when the user finishes rating. Gives you the final rating value as a whole number (required)

Try it out

You can try it out with Expo here. Or you can also run the example app locally.

Motivation

One of my friends showed me this Star Rating feature in Bootstrap and it looks really interesting. So I challenged myself to re-implement it in React Native.

Followed by that, for v3, I recreated the Airbnb ratings component and added it to this repo, in case others find this useful. It works out of the box and is quite functional.

Also this is my first npm module :confetti_ball:

Feedback

This repo is being actively manitained. Feel free to open a new Issue with a Feature Request or submit a PR with an Enhancement.

8.0.4

3 years ago

8.1.0

3 years ago

8.0.3

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

7.6.1

3 years ago

7.6.0

3 years ago

7.5.0

3 years ago

7.4.0

3 years ago

7.3.0

4 years ago

7.2.0

4 years ago

7.1.0

4 years ago

7.0.0

4 years ago

6.5.0

5 years ago

6.4.0

5 years ago

6.3.1

5 years ago

6.3.0

5 years ago

6.2.0

5 years ago

6.1.0

5 years ago

6.0.0

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.0

6 years ago

5.0.0

6 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago