Merge pull request #203 from talhaazhar/master

Added Secondary Color Prop to dynamically change color as Progress increases for #188
This commit is contained in:
Markus Lindqvist 2019-09-12 15:40:17 +03:00 committed by GitHub
commit 72e1d2d1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 4 deletions

View File

@ -95,6 +95,7 @@ prefill | number (0-100) | 0 | Initial
duration | number | 500 | Duration of animation in ms
easing | function | Easing.out(Easing.ease) | Animation easing function
onAnimationComplete | function | | Function that's invoked when the animation completes (both on mount and if called with `.animate()`)
tintColorSecondary | string | the same as tintColor | To change fill color from tintColor to tintColorSecondary as animation progresses
`AnimatedCircularProgress` also exposes the following functions:
@ -107,7 +108,7 @@ reAnimate | (prefill: number, toVal: number, duration: number, ease: function)
```sh
git clone https://github.com/bgryszko/react-native-circular-progress.git
cd react-native-circular-progress/example
cd react-native-circular-progress/example-app
yarn
yarn start
```

View File

@ -69,7 +69,8 @@ export default class App extends React.Component {
width={15}
backgroundWidth={5}
fill={fill}
tintColor="#00e0ff"
tintColor="#00ff00"
tintColorSecondary="#ff0000"
backgroundColor="#3d5875"
arcSweepAngle={240}
rotation={240}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 353 KiB

After

Width:  |  Height:  |  Size: 3.2 MiB

View File

@ -35,7 +35,7 @@ export default class AnimatedCircularProgress extends React.PureComponent {
const toValue = toVal >= 0 ? toVal : this.props.fill;
const duration = dur || this.props.duration;
const easing = ease || this.props.easing;
const anim = Animated.timing(this.state.fillAnimation, {
toValue,
easing,
@ -46,10 +46,23 @@ export default class AnimatedCircularProgress extends React.PureComponent {
return anim;
}
animateColor() {
if (!this.props.tintColorSecondary) {
return this.props.tintColor
}
const tintAnimation = this.state.fillAnimation.interpolate({
inputRange: [0, 100],
outputRange: [this.props.tintColor, this.props.tintColorSecondary]
})
return tintAnimation
}
render() {
const { fill, prefill, ...other } = this.props;
return <AnimatedProgress {...other} fill={this.state.fillAnimation} />;
return <AnimatedProgress {...other} fill={this.state.fillAnimation} tintColor={this.animateColor()} />;
}
}