Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-swipeable-rating

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-swipeable-rating

Star rating component with support for swipe and / or touch selection

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
235
decreased by-20.07%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-swipeable-rating

Star rating component with support for swipe and / or touch selection

Example

Usage

react-native-vector-icons package is required, set it up if you haven't already.

install > npm i react-native-swipeable-rating

Basic example

import React, { Component } from 'react';
import { View } from 'react-native';
import SwipeableRating from 'react-native-swipeable-rating';

class MyStarRating extends Component {
  state = {
    rating: 0
  }

  handleRating = (rating) => {
    this.setState({rating});
  }

  render(){
    return(
      <View style={{marginHorizontal: 30}}>
        <SwipeableRating
          rating={this.state.rating}
          size={32}
          gap={4}
          onPress={this.handleRating}
          xOffset={30}
        />
      </View>
    )
  }
}

See the full example app

There are a few different ways the component can be used:

  • The above example works with swiping and tapping on individual stars.
  • rating={n}, swipeable={false} and no onPress will make it a dumb/static component that displays a rating.
  • swipeable={false} with an onPress function will make the individual stars a tappable TouchableOpacity.
  • if you use allowHalves you will also need to change minRating to 0.5

Props

Prop nametypedefaultDescRequired?
ratingnumberThe rating
onPressfunctionThe function to be called when swiping or tapping
swipeablebooleantrueAllow/disallow swiping the component to change the rating
xOffsetnumber0The offset from the left of the screen to the start of the component (ignore if swipeable={false})no but you will almost definitely need to change it!
styleobjectStyles the rating container
colorstring'crimson'Color applied to the default star icon
emptyColorstring'crimson'Color applied to the default empty star icon
sizenumber24The size applied to the default icons
gapnumber0marginRight applied to the default icons
minRatingnumber1The minimum rating to allow
maxRatingnumber5The maximum rating to allow / amount of stars to display
allowHalvesbooleanfalseAllow ratings to go up in increments of 0.5 instead of 1
filledIconstring or function'star'The MaterialIcons icon to use for the filled star OR your custom component function (receives size, gap, number args)
halfFilledIconstring or function'star-half'The MaterialIcons icon to use for the half filled star OR your custom component function (receives size, gap, number args)
emptyIconstring or function'star-border'The MaterialIcons icon to use for the empty star OR your custom component function (receives size, gap, number args)

You must make your custom icon components size (+ gap, if you use it) total width, so the correct swipe distances can be calculated.

size, gap, color, emptyColor, n (the icon's rating number (index) beginning at 1) are passed to the custom icon functions for convenience.

Keywords

FAQs

Package last updated on 20 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc