Skip to content

Commit

Permalink
Dynamic fill color addressing Issue #188
Browse files Browse the repository at this point in the history
  • Loading branch information
talhaazhar committed Sep 3, 2019
1 parent c279904 commit 4e0ca4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
```
Expand Down
3 changes: 2 additions & 1 deletion example-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
19 changes: 16 additions & 3 deletions src/AnimatedCircularProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

console.log("THE KEY: " + JSON.stringify(this.state.fillAnimation));
const anim = Animated.timing(this.state.fillAnimation, {
toValue,
easing,
Expand All @@ -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()} />;
}
}

Expand All @@ -65,4 +78,4 @@ AnimatedCircularProgress.defaultProps = {
duration: 500,
easing: Easing.out(Easing.ease),
prefill: 0,
};
};

0 comments on commit 4e0ca4a

Please sign in to comment.