Skip to content

Commit

Permalink
(feat): add a tint color
Browse files Browse the repository at this point in the history
  • Loading branch information
Monir-Shembesh committed Mar 27, 2020
1 parent e343ab4 commit 501fb13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 12 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ declare module 'react-native-circular-progress' {
tintColor?: string;

/**
* Change the fill color from tintColor to tintColorSecondary as animation progresses.
*
* Change the fill color from the first to the second color as animation progresses.
*
* @type {string}
* @default 'undefined'
*/
secondTintColor?: string;

/**
* Change the fill color from the second color to the third color as animation progresses.
*
* @type {string}
* @default 'undefined'
*/
tintColorSecondary?: string;
thirdTintColor?: string;

/**
* Current progress / tint transparency
Expand Down Expand Up @@ -181,7 +189,7 @@ declare module 'react-native-circular-progress' {

export class AnimatedCircularProgress extends React.Component<
AnimatedCircularProgressProps
> {
> {
/**
* Animate the progress bar to a specific value
*
Expand Down
12 changes: 8 additions & 4 deletions src/AnimatedCircularProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class AnimatedCircularProgress extends React.PureComponent {
const duration = dur || this.props.duration;
const easing = ease || this.props.easing;
const useNativeDriver = this.props.useNativeDriver;

const anim = Animated.timing(this.state.fillAnimation, {
useNativeDriver,
toValue,
Expand All @@ -49,13 +49,17 @@ export default class AnimatedCircularProgress extends React.PureComponent {
}

animateColor() {
if (!this.props.tintColorSecondary) {
if (!this.props.secondTintColor) {
return this.props.tintColor
}

if (!this.props.thirdTintColor) {
return this.props.secondTintColor
}

const tintAnimation = this.state.fillAnimation.interpolate({
inputRange: [0, 100],
outputRange: [this.props.tintColor, this.props.tintColorSecondary]
inputRange: [0, 50, 100],
outputRange: [this.props.tintColor, this.props.secondTintColor, this.props.thirdTintColor]
})

return tintAnimation
Expand Down

1 comment on commit 501fb13

@Monir-Shembesh
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After testing with only two tint colors the progress circle felt limited. For example, going from the color 'green' to the color 'red' at 100% produces a weird darkish 'green' color at 50%. Where as, some developers such as myself would like the 50% bar to be a yellow tint color. The solution is simple and straight forward, I have added a third tint color to enable a smoother color transition.

Please sign in to comment.