Merge pull request #295 from jkhusanov/master

Add delay to animated circular progress
This commit is contained in:
Markus Lindqvist 2022-05-20 09:33:03 +03:00 committed by GitHub
commit f0a87ee530
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -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

8
index.d.ts vendored
View File

@ -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}

View File

@ -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)
);
@ -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);
@ -86,6 +88,7 @@ AnimatedCircularProgress.propTypes = {
easing: PropTypes.func,
onAnimationComplete: PropTypes.func,
useNativeDriver: PropTypes.bool,
delay: PropTypes.number,
};
AnimatedCircularProgress.defaultProps = {
@ -93,4 +96,5 @@ AnimatedCircularProgress.defaultProps = {
easing: Easing.out(Easing.ease),
prefill: 0,
useNativeDriver: false,
delay: 0,
};