diff --git a/Bar.js b/Bar.js index 2c1d50c..5bad252 100644 --- a/Bar.js +++ b/Bar.js @@ -9,6 +9,7 @@ const BAR_WIDTH_ZERO_POSITION = export default class ProgressBar extends Component { static propTypes = { animated: PropTypes.bool, + animateReset: PropTypes.bool, borderColor: PropTypes.string, borderRadius: PropTypes.number, borderWidth: PropTypes.number, @@ -29,6 +30,7 @@ export default class ProgressBar extends Component { static defaultProps = { animated: true, + animateReset: true, borderRadius: 4, borderWidth: 1, color: 'rgba(0, 122, 255, 1)', @@ -79,12 +81,16 @@ export default class ProgressBar extends Component { : Math.min(Math.max(props.progress, 0), 1); if (props.animated) { - const { animationType, animationConfig } = this.props; - Animated[animationType](this.state.progress, { - ...animationConfig, - toValue: progress, - useNativeDriver: props.useNativeDriver, - }).start(); + if (!props.animateReset && progress === 0) { + this.state.progress.setValue(progress); + } else { + const { animationType, animationConfig } = this.props; + Animated[animationType](this.state.progress, { + ...animationConfig, + toValue: progress, + useNativeDriver: props.useNativeDriver, + }).start(); + } } else { this.state.progress.setValue(progress); } diff --git a/README.md b/README.md index 59ad387..42e331b 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ All of the props under *Properties* in addition to the following: |**`borderRadius`**|Rounding of corners, set to `0` to disable. |`4`| |**`useNativeDriver`**|Use native driver for the animations. |`false`| |**`animationConfig`**|Config that is passed into the `Animated` function. |`{ bounciness: 0 }`| +|**`animateReset`**|Whether or not to animate bar when progress is set to 0. |`true`| |**`animationType`**|Animation type to animate the progress, one of: `decay`, `timing`, `spring`. |`spring`| ### `Progress.Circle`