| 54 | } |
| 55 | |
| 56 | componentDidUpdate(prevProps) { |
| 57 | if (prevProps.indeterminate !== this.props.indeterminate) { |
| 58 | if (this.props.indeterminate) { |
| 59 | this.spin(); |
| 60 | } else { |
| 61 | Animated.spring(this.state.rotation, { |
| 62 | toValue: this.rotationValue > 0.5 ? 1 : 0, |
| 63 | useNativeDriver: false |
| 64 | }).start(endState => { |
| 65 | if (endState.finished) { |
| 66 | this.state.rotation.setValue(0); |
| 67 | } |
| 68 | }); |
| 69 | } |
| 70 | } |
| 71 | const progress = this.props.indeterminate |
| 72 | ? indeterminateProgress || 0 |
| 73 | : Math.min(Math.max(this.props.progress, 0), 1); |
| 74 | if (progress !== this.progressValue) { |
| 75 | if (this.props.animated) { |
| 76 | Animated.spring(this.state.progress, { |
| 77 | toValue: progress, |
| 78 | bounciness: 0, |
| 79 | useNativeDriver: false |
| 80 | }).start(); |
| 81 | } else { |
| 82 | this.state.progress.setValue(progress); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | componentWillUnmount() { |
| 88 | this.state.progress.removeAllListeners(); |