Skip to content

Repository files navigation

react-native-rewards

npm version

Library is strongly inspired by react-rewards created by The Develobear!

react-native-rewards demo

## Getting started

$ npm install react-native-rewards --save

$ yarn add react-native-root-view-background

Library is 100% javascript so, there is no need to do native linking

Usage

using props:

importRewardsComponentfrom'react-native-rewards';importReact,{Component,createRef}from'react';classAppextendsComponent{state={animationState: 'rest',}render(){const{ animationState }=this.state;return(<RewardsComponentanimationType="confetti"state={animationState}onRest={()=>this.setState({animationState: 'rest'})}><TouchableOpacityonPress={()=>this.setState({animationState: 'reward'})}style={styles.buttonProps}><Textstyle={styles.buttonText}>+</Text></TouchableOpacity></RewardsComponent>)}}

using ref:

importRewardsComponentfrom'react-native-rewards';importReact,{Component,createRef}from'react';classAppextendsComponent{constructor(props){super(props);this.rewardsComponent=createRef();}render(){return(<RewardsComponentref={this.rewardsComponent}animationType="emoji"><TouchableOpacityonPress={()=>this.rewardsComponent.current.rewardMe()}style={styles.button}><Imagesource={require('./assets/cup.png')}style={styles.icon}/></TouchableOpacity></RewardsComponent>)}}

Props

nametypedescriptionrequireddefault
childrenReact Elementcontent to animate e.g. ButtonYES
initialSpeedNumber/Floatinitial speed of particesNO1
spreadNumber/FloatMultiplier of distance beetween particesNO1
deaccelerationNumber/FloatMultiplier how fast partices deaccelerate in firt phaseNO1
rotationXSpeedNumber/FloatRotation speed multiplier in X axisNO5
rotationZSpeedNumber/FloatRotation speed multiplier in Z axisNO5
particiesCountNumber/IntegerPartices count in reward animationNO20
colorsArrayColors used to generate confettiNOSome colors :)
emojiArrayEmojis used to generate confettiNO['👍','😊','🎉']
animationTypeStringType of animation confetti/emojiNOconfetti
stateStringState of animation, changing of this value triggers animationNOrest
onRestFunctionCallback when animation goes to rest stateNO

Methods

You can call this method by using refs of component

  • rewardMe - Triggers reward animation
  • punishMe - Triggers punish animation

Notes for local development

You need to have facebook watchman installed

  1. cd example
  2. yarn
  3. yarn start
  4. yarn run sync in another terminal window (doesn't matter where)

If you have any issues, you can clear your watches using watchman watch-del-all and try again.

Author

Feel free to ask me qustion on Twitter @JanRomaniak!

About

Reward your users for little things and make them smile!

Resources

Stars

43 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages