mirror of
https://github.com/bartgryszko/react-native-circular-progress.git
synced 2026-01-18 16:13:10 +00:00
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:
commit
72e1d2d1b4
@ -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
|
||||
```
|
||||
|
||||
@ -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}
|
||||
|
||||
BIN
screenshot.gif
BIN
screenshot.gif
Binary file not shown.
|
Before Width: | Height: | Size: 353 KiB After Width: | Height: | Size: 3.2 MiB |
@ -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()} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user