0.0.5 • Published 10 months ago

react-native-gogo-spin v0.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

react-native-gogo-spin

supports iOS supports Android npm npm license | Example | | :-------------------------------------- | | Example |

Installation

yarn add react-native-gogo-spin

or

npm install react-native-gogo-spin --save

Notice

worked in react native web and ios android ,you can custom each pie base on array you passed in,like Flatlist;check the example to seek the usage;

Examples

React Native example

Code

export const App = () => {
  const prize=[1,2,3,4,5,6]
  const spinRef = useRef<React.ElementRef<typeof GoGoSpin>>(null);
  const doSpin = () => {
    const getIdx = ~~(Math.random() * prize.length);
    spinRef.current.doSpinAnimate(getIdx);
  };
  const onEndSpin = (endSuccess: boolean) => {
    console.log('endSuccess', endSuccess);
  };
  return (
    <View style={styles.container}>
      <View style={styles.centerWheel}>
        <GoGoSpin
          onEndSpinCallBack={onEndSpin}
          notShowDividLine={true}
          spinDuration={2000}
          spinReverse={true}
          spinTime={3}
          ref={spinRef}
          width={SIZE}
          height={SIZE}
          radius={SIZE / 2}
          data={prize}
          offsetEnable={true}
          source={require('./images/wheel.png')}
          renderItem={(data, i) => {
            return (
              <View key={i} style={styles.itemWrapper}>
                <Text style={styles.prizeText}>{data.name}</Text>
                <Image source={data.image} style={{ width: 40, height: 40 }} />
              </View>
            );
          }}
        />
        <TouchableOpacity style={{ position: 'absolute' }} onPress={doSpin}>
          <Image source={require('./images/btn.png')} style={{ width: 105, height: 124 }} />
        </TouchableOpacity>
      </View>
    </View>
  );
};

Methods

PropDefaultTypeDescription
doSpinAnimate-(idx: number) => voidspin to the given index in data prop

Props

PropDefaultTypeDescription
data(required)-arrayLike data in flatlist
renderItem(required)-(data,index)=>React.ReactElementLike renderItem in flatlist
width/height/radius(required)-numberSize of the wheel
source-ImageSourcePropTypethis props shows a background image if it exist
onEndSpinCallBack-(finish: boolean) => voidcall after spin end
notShowDividLinefalsebooleanif show the dividing line between each pie
offsetEnablefalsebooleanfalse will point to the center of the pie ,true will randomly point to the section of the pie
offsetPercent0.9number 1-0.1time to offset random angle only works if offsetEnable is true
spinReversefalsebooleanspin reverse
wheelStyle8000StyleProp<ViewStyle>the style of the outside wheel
spinTime8numberthe number of the wheel make turns after it point to the prize
spinDuration8000numberThe time(ms) whole spin animation last
innerHeight/innerWidth50numberitem in pie default size

Author

282931