From a9846da9fa638fdbb3073cb8f3fbe67d8fba94fe Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 25 Feb 2016 16:59:22 -0800 Subject: [PATCH] support plain numbers in add and multiply operators Summary:This adds support for passing plain numbers into the add and multiply operators. This can be useful if you want to have one AnimatedValue for a component that is say a scale 0 -> 1 and then animated many style properties accordingly using derivative Animated values. Thoughts? As far as implementation, there may be more performant implementations that do not require creating a whole new AnimatedValue for every static number. I am open to suggestion. Closes https://github.com/facebook/react-native/pull/6154 Differential Revision: D2979962 Pulled By: vjeux fb-gh-sync-id: b5ecb568b4c64b995dc4100991f02c17f0dd97dd shipit-source-id: b5ecb568b4c64b995dc4100991f02c17f0dd97dd --- Libraries/Animated/src/AnimatedImplementation.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 01b701a77..830ab929d 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -844,10 +844,10 @@ class AnimatedAddition extends AnimatedWithChildren { _a: Animated; _b: Animated; - constructor(a: Animated, b: Animated) { + constructor(a: Animated | number, b: Animated | number) { super(); - this._a = a; - this._b = b; + this._a = typeof a === 'number' ? new AnimatedValue(a) : a; + this._b = typeof b === 'number' ? new AnimatedValue(b) : b; } __getValue(): number { @@ -873,10 +873,10 @@ class AnimatedMultiplication extends AnimatedWithChildren { _a: Animated; _b: Animated; - constructor(a: Animated, b: Animated) { + constructor(a: Animated | number, b: Animated | number) { super(); - this._a = a; - this._b = b; + this._a = typeof a === 'number' ? new AnimatedValue(a) : a; + this._b = typeof b === 'number' ? new AnimatedValue(b) : b; } __getValue(): number {