Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to use Animated #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 40 additions & 43 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

var React = require('react-native');
var tweenState = require('react-tween-state');

var {
Image,
StyleSheet,
TouchableHighlight,
View
View,
Animated,
Easing,
} = React;

var styles = require('./styles');
Expand Down Expand Up @@ -48,7 +49,6 @@ var ProgressHUDMixin = {
};

var ProgressHUD = React.createClass({
mixins: [tweenState.Mixin],

contextTypes: {
showProgressHUD: React.PropTypes.func.isRequired,
Expand Down Expand Up @@ -76,30 +76,27 @@ var ProgressHUD = React.createClass({

getInitialState() {
return {
rotate_deg: 0
rotate_deg: new Animated.Value(0),
};
},

componentDidMount() {
// Kick off rotation animation
this._rotateSpinner();

// Set rotation interval
this.interval = setInterval(() => {
this._rotateSpinner();
}, SPIN_DURATION);
},

componentWillUnmount() {
clearInterval(this.interval);
componentDidUpdate: function(prevProps, prevState) {
this.props.isVisible!=prevProps.isVisible&&this.props.isVisible&&this._rotateSpinner();
},

_rotateSpinner() {
this.tweenState('rotate_deg', {
easing: tweenState.easingTypes.linear,
duration: SPIN_DURATION,
endValue: this.state.rotate_deg === 0 ? 360 : this.state.rotate_deg + 360
});

if(!this.props.isVisible)return;

if(this.state.rotate_deg._value===1){
this.state.rotate_deg.setValue(0);
}

Animated.timing(this.state.rotate_deg,{
toValue:1,
duration:SPIN_DURATION,
easing: Easing.linear,
}).start(this._rotateSpinner);
},

_clickHandler() {
Expand All @@ -114,11 +111,6 @@ var ProgressHUD = React.createClass({
return <View />;
}

// Set rotation property value
var deg = Math.floor(
this.getTweeningValue('rotate_deg')
).toString() + 'deg';

return (
/*jshint ignore:start */
<TouchableHighlight
Expand All @@ -131,25 +123,30 @@ var ProgressHUD = React.createClass({
activeOpacity={1}
>
<View
style={[styles.container, {
left: this.getTweeningValue('left')
}]}
style={styles.container}
>
<Image
<Animated.View
style={[styles.spinner, {
backgroundColor: this.props.color,
transform: [
{rotate: deg}
]
}]}
source={{
uri: 'data:image/png;base64,' + images['1x'],
isStatic: true
}}
>
<View style={styles.inner_spinner}>
</View>
</Image>
transform: [
{rotate: this.state.rotate_deg.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
})}
]
}]}>
<Image//Animated.Image have issue in Android
style={[styles.spinner, {
backgroundColor: this.props.color,
}]}
source={{
uri: 'data:image/png;base64,' + images['1x'],
isStatic: true
}}
>
<View style={styles.inner_spinner}>
</View>
</Image>
</Animated.View>
</View>
</TouchableHighlight>
/*jshint ignore:end */
Expand Down