Skip to content

Add a third tint color to enhance the UI experience #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ 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
secondTintColor | string | the same as tintColor | To change fill color from the first color to the second color as animation progresses
thirdTintColor | string | the same as secondColor | To change fill color from the second color to the third color as animation progresses

`AnimatedCircularProgress` also exposes the following functions:

Expand Down
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