From cbe60b1d4ccc86416bb861a583d41ffd7e3c82b9 Mon Sep 17 00:00:00 2001 From: Pedro Ovalle Date: Fri, 27 Jul 2018 13:45:31 -0500 Subject: [PATCH 1/2] Added animateReset prop and information. --- Bar.js | 18 ++++++++++++------ README.md | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Bar.js b/Bar.js index 2c1d50c..dd0aad0 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` From dee83a7558b99ac6c4e4eefe8297db7be1840ce2 Mon Sep 17 00:00:00 2001 From: Pedro Ovalle Date: Fri, 27 Jul 2018 13:57:50 -0500 Subject: [PATCH 2/2] Changed '==' to '===' for Travis CI --- Bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bar.js b/Bar.js index dd0aad0..5bad252 100644 --- a/Bar.js +++ b/Bar.js @@ -81,7 +81,7 @@ export default class ProgressBar extends Component { : Math.min(Math.max(props.progress, 0), 1); if (props.animated) { - if (!props.animateReset && progress == 0) { + if (!props.animateReset && progress === 0) { this.state.progress.setValue(progress); } else { const { animationType, animationConfig } = this.props;