Created
October 1, 2016 05:19
-
-
Save blackavec/1c05890fe80ce8b0f79708c46349d6c2 to your computer and use it in GitHub Desktop.
improvement on progress bar - https://github.com/lwansbrough/react-native-progress-bar
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
import React, { | |
Component, | |
} from 'react'; | |
import { | |
StyleSheet, | |
Text, | |
View, | |
Animated, | |
Easing, | |
} from 'react-native'; | |
export default class ProgressBar extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
progress: new Animated.Value(this.props.initialProgress || 0), | |
}; | |
this.props.style = styles; | |
this.props.easing = Easing.linear(Easing.ease); | |
this.props.easingDuration = 100; | |
} | |
componentDidUpdate(prevProps, prevState) { | |
if (this.props.progress >= 0 && this.props.progress != prevProps.progress) { | |
this.update(); | |
} | |
} | |
render() { | |
let fillWidth = this.state.progress.interpolate({ | |
inputRange: [0, 1], | |
outputRange: [0 * this.props.style.width, 1 * this.props.style.width], | |
}); | |
return ( | |
<View style={[styles.background, this.props.backgroundStyle, this.props.style]}> | |
<Animated.View style={[styles.fill, this.props.fillStyle, { width: fillWidth }]}/> | |
</View> | |
); | |
} | |
update() { | |
Animated.timing(this.state.progress, { | |
easing: this.props.easing, | |
duration: this.props.easingDuration, | |
toValue: this.props.progress / 100 | |
}).start(); | |
} | |
} | |
var styles = StyleSheet.create({ | |
background: { | |
backgroundColor: '#bbbbbb', | |
height: 4, | |
overflow: 'hidden' | |
}, | |
fill: { | |
backgroundColor: '#3b5998', | |
height: 4 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not working. If I am passing progress value but I can't see it filled.