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

Allow for a duration of 0 #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions createAnimatableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const INTERPOLATION_STYLE_PROPERTIES = [
'tintColor',
];

const DEFAULT_DURATION = 1000;

const ZERO_CLAMPED_STYLE_PROPERTIES = ['width', 'height'];

// Create a copy of `source` without `keys`
Expand Down Expand Up @@ -94,6 +96,15 @@ function makeInterpolatedStyle(compiledAnimation, animationValue) {
return wrapStyleTransforms(style);
}

function getDurationDefault(duration, fallback) {
if (typeof duration === 'number' && duration >= 0) {
return duration;
} else if (typeof fallback === 'number' && fallback >= 0) {
return fallback;
}
return DEFAULT_DURATION;
}

function transitionToValue(
property,
transitionValue,
Expand All @@ -110,7 +121,7 @@ function transitionToValue(
? Animated.timing(transitionValue, {
toValue,
delay,
duration: duration || 1000,
duration: getDurationDefault(duration),
easing:
typeof easing === 'function'
? easing
Expand Down Expand Up @@ -408,7 +419,7 @@ export default function createAnimatableComponent(WrappedComponent) {
toValue,
easing,
isInteraction: iterationCount <= 1,
duration: duration || this.props.duration || 1000,
duration: getDurationDefault(duration, this.props.duration),
useNativeDriver,
delay: iterationDelay || 0,
};
Expand Down