From 7ead7dd49f0cf30633584da5cd57073913ca8456 Mon Sep 17 00:00:00 2001 From: Chris Pitt Date: Tue, 25 Jun 2019 11:44:37 +0100 Subject: [PATCH] Allow for a duration of 0 by using an explicit numeric check rather than a falsey check. --- createAnimatableComponent.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/createAnimatableComponent.js b/createAnimatableComponent.js index 8f9fb03..256b2bb 100644 --- a/createAnimatableComponent.js +++ b/createAnimatableComponent.js @@ -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` @@ -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, @@ -110,7 +121,7 @@ function transitionToValue( ? Animated.timing(transitionValue, { toValue, delay, - duration: duration || 1000, + duration: getDurationDefault(duration), easing: typeof easing === 'function' ? easing @@ -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, };