forked from yasemincidem/react-native-flip-card-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlipCard.js
67 lines (58 loc) · 1.61 KB
/
FlipCard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from "react";
import {
Animated,
Easing,
TouchableOpacity,
Text,
View
} from "react-native";
const styles = {
animatedContainer: {
flex: 1
}
};
var FlipCard = React.createClass({
getInitialState(){
return {
animatedValue: new Animated.Value(0),
isFlipped: true,
}
},
componentDidUpdate(prevProp, prevState) {
if (this.state.isFlipped !== prevState.isFlipped) {
this._flippedCard();
}
},
_flipToggleCard() {
this.setState({isFlipped: !this.state.isFlipped});
},
_flippedCard() {
Animated.spring(this.state.animatedValue, {
toValue: 0, // Returns to the start
velocity: this.props.velocity, // Velocity makes it move
tension: this.props.tension, // Slow
friction: this.props.friction, // Oscillate a lot
}).start();
},
render() {
const rotateX = this.state.animatedValue.interpolate({
inputRange: [0, 0.5, 1],
outputRange: ['0deg', '360deg', '0deg']
});
return (
<View style={styles.animatedContainer}>
<Animated.View
style={[styles.animatedContainer,{transform: [{rotateX}]}]}>
{this.flippedCardView(this.state.isFlipped)}
</Animated.View>
</View>);
},
flippedCardView(isFlipped) {
if (isFlipped) {
return this.props.renderFront;
} else {
return this.props.renderBack;
}
}
});
module.exports = FlipCard;