Skip to content
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

Add "noAnimateOnMount" prop #194

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ You can create your own simple transitions of a style property of your own choos
|**`onAnimationBegin`**|A function that is called when the animation has been started. |*None*|
|**`onAnimationEnd`**|A function that is called when the animation has been completed successfully or cancelled. Function is called with an `endState` argument, refer to `endState.finished` to see if the animation completed or not. |*None*|
|**`useNativeDriver`**|Whether to use native or JavaScript animation driver. Native driver can help with performance but cannot handle all types of styling and requires you to integrate that module on iOS. |`false`|
|**`noAnimateOnMount`**|Whether to not animate the component when it mounts. Component will be animated only when it receives new props. |`false`|

### Imperative Usage

Expand Down
30 changes: 21 additions & 9 deletions createAnimatableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,22 @@ export default function createAnimatableComponent(WrappedComponent) {
delay,
onAnimationBegin,
onAnimationEnd,
noAnimateOnMount,
} = this.props;
if (animation) {
const startAnimation = () => {
onAnimationBegin();
this.startAnimation(duration, 0, onAnimationEnd);
this.delayTimer = null;
};
if (delay) {
this.delayTimer = setTimeout(startAnimation, delay);
if (noAnimateOnMount) {
this.startAnimation(0, 0);
} else {
startAnimation();
const startAnimation = () => {
onAnimationBegin();
this.startAnimation(duration, 0, onAnimationEnd);
this.delayTimer = null;
};
if (delay) {
this.delayTimer = setTimeout(startAnimation, delay);
} else {
startAnimation();
}
}
}
}
Expand Down Expand Up @@ -390,11 +395,18 @@ export default function createAnimatableComponent(WrappedComponent) {
easing = Easing.out(easing);
}

let effectiveDuration = 1000;
if (typeof duration === 'number') {
effectiveDuration = duration;
} else if (typeof this.props.duration === 'number') {
effectiveDuration = this.props.duration;
}

Animated.timing(animationValue, {
toValue,
easing,
isInteraction: iterationCount <= 1,
duration: duration || this.props.duration || 1000,
duration: effectiveDuration,
useNativeDriver,
}).start(endState => {
currentIteration += 1;
Expand Down