Created
July 22, 2015 02:48
-
-
Save cssoul/eda63b173311a323653b to your computer and use it in GitHub Desktop.
React Native Loading Animation
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
/** | |
* LoadingView | |
*/ | |
'use strict'; | |
var React = require('react-native'); | |
var { | |
TouchableWithoutFeedback, | |
Animated, | |
StyleSheet, | |
Image, | |
View, | |
Easing | |
} = React; | |
var TIMES = 400; | |
var LoadingView = React.createClass({ | |
getInitialState() { | |
return { | |
angle: new Animated.Value(0), | |
}; | |
}, | |
componentDidMount() { | |
this._animate(); | |
}, | |
_animate() { | |
this.state.angle.setValue(0); | |
this._anim = Animated.timing(this.state.angle, { | |
toValue: 360*TIMES, | |
duration: 800*TIMES, | |
easing: Easing.linear | |
}).start(this._animate); | |
}, | |
componentDidUnmount:function(){ | |
}, | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Animated.Image | |
source={{uri: 'MGJControls.bundle/loading_circle.png'}} | |
style={[ | |
styles.rotateCard, | |
{transform: [ | |
{rotate: this.state.angle.interpolate({ | |
inputRange: [0, 360], | |
outputRange: ['0deg', '360deg'] | |
})}, | |
]}]}> | |
</Animated.Image> | |
</View> | |
); | |
} | |
}); | |
var styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center' | |
}, | |
rotateCard: { | |
width:35, | |
height:35, | |
justifyContent:'center', | |
backgroundColor:'transparent' | |
} | |
}); | |
module.exports = LoadingView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would this work to animate, for example, from 0 to 270deg and stop?