Created
February 20, 2017 10:17
-
-
Save kyle-ssg/cb6d0d4d805a3fb74b68b88196e1ff00 to your computer and use it in GitHub Desktop.
animates opacity on press
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Animation = class extends Component { | |
displayName: 'Animation' | |
constructor (props, context) { | |
super(props, context); | |
this.state = { opacity: 1 }; | |
} | |
toggleFade = () => { | |
//toggle opacity | |
this.animate(this.state.opacity ? 0.5 : 1) | |
} | |
animate = (toValue) => { | |
LayoutAnimation.easeInEaseOut(); | |
this.setState({ opacity: toValue }) | |
} | |
render () { | |
return ( | |
<TouchableOpacity activeOpacity={1} onPressIn={this.toggleFade}> | |
<Text style={{opacity:this.state.opacity}}> | |
Hi | |
</Text> | |
</TouchableOpacity> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment