diff --git a/ProgressBar.js b/ProgressBar.js index a21e79e..25c9e10 100644 --- a/ProgressBar.js +++ b/ProgressBar.js @@ -31,7 +31,8 @@ var ProgressBar = React.createClass({ getInitialState() { return { - progress: new Animated.Value(this.props.initialProgress || 0) + progress: new Animated.Value(this.props.initialProgress || 0), + calculatedWidth: 0 }; }, @@ -45,11 +46,17 @@ var ProgressBar = React.createClass({ var fillWidth = this.state.progress.interpolate({ inputRange: [0, 1], - outputRange: [0 * this.props.style.width, 1 * this.props.style.width], + outputRange: [0 * (this.props.style.width || this.state.calculatedWidth ), + 1 * (this.props.style.width || this.state.calculatedWidth)] }); return ( - + { + if (!this.props.style.width) { + this.setState({calculatedWidth: event.nativeEvent.layout.width}) + } + }}> );