Skip to content

Commit

Permalink
Merge pull request #295 from jkhusanov/master
Browse files Browse the repository at this point in the history
Add delay to animated circular progress
  • Loading branch information
markusl authored May 20, 2022
2 parents f6a56fa + b769237 commit f0a87ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Name | Type | Default value | Descrip
--------------------|------------------------|-------------------------|--------------
prefill | number (0-100) | 0 | Initial fill-value before animation starts
duration | number | 500 | Duration of animation in ms
delay | number | 0 | Delay 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()`)
onFillChange | function | | Function that returns current progress on every change
Expand Down
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ declare module 'react-native-circular-progress' {
*/
duration?: number;

/**
* Delay of animation in ms
*
* @type {number}
* @default 0
*/
delay?: number;

/**
*
* @type {Function}
Expand Down
6 changes: 5 additions & 1 deletion src/AnimatedCircularProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class AnimatedCircularProgress extends React.PureComponent {
this.state = {
fillAnimation: new Animated.Value(props.prefill),
};
if(props.onFillChange){
if (props.onFillChange) {
this.state.fillAnimation.addListener(({ value }) =>
props.onFillChange(value)
);
Expand Down Expand Up @@ -41,12 +41,14 @@ 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 delay = this.props.delay;

const anim = Animated.timing(this.state.fillAnimation, {
useNativeDriver,
toValue,
easing,
duration,
delay,
});
anim.start(this.props.onAnimationComplete);

Expand Down Expand Up @@ -86,11 +88,13 @@ AnimatedCircularProgress.propTypes = {
easing: PropTypes.func,
onAnimationComplete: PropTypes.func,
useNativeDriver: PropTypes.bool,
delay: PropTypes.number,
};

AnimatedCircularProgress.defaultProps = {
duration: 500,
easing: Easing.out(Easing.ease),
prefill: 0,
useNativeDriver: false,
delay: 0,
};

0 comments on commit f0a87ee

Please sign in to comment.