From 9eb7629ac66abc23b91b81d420891d68bbd4f578 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Tue, 3 May 2022 12:04:02 -0700 Subject: [PATCH] Add Animated.Numeric Flow type Summary: Changelog: [General][Added] - Add `Animated.Numeric` Flow type Adds a Flow type to represent the various Animated node types that evaluate to numeric values and can be `interpolate()`d. I'm including `AnimatedInterpolation` as "numeric" here even though it can technically evaluate either to a number or to a string, depending on its config. Note that calling `interpolate()` on a string-valued `AnimatedInterpolation` is a runtime error. In a future diff, I'm planning to add a type argument to `AnimatedInterpolation` (and its config type), at which point we can refine `Animated.Numeric` to correctly include only `AnimatedInterpolation`. Reviewed By: javache Differential Revision: D35869375 fbshipit-source-id: 2ff6754f1a5abc68c9da2c6836872c2022b25676 --- Libraries/Animated/Animated.js | 4 ++-- Libraries/Animated/AnimatedImplementation.js | 13 +++++++++++++ Libraries/Animated/AnimatedMock.js | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Libraries/Animated/Animated.js b/Libraries/Animated/Animated.js index 70beabf56a98a9..88fd9dbb188dbe 100644 --- a/Libraries/Animated/Animated.js +++ b/Libraries/Animated/Animated.js @@ -16,8 +16,8 @@ import typeof AnimatedSectionList from './components/AnimatedSectionList'; import typeof AnimatedText from './components/AnimatedText'; import typeof AnimatedView from './components/AnimatedView'; -const AnimatedMock = require('./AnimatedMock'); -const AnimatedImplementation = require('./AnimatedImplementation'); +import * as AnimatedMock from './AnimatedMock'; +import * as AnimatedImplementation from './AnimatedImplementation'; const Animated = ((Platform.isTesting ? AnimatedMock diff --git a/Libraries/Animated/AnimatedImplementation.js b/Libraries/Animated/AnimatedImplementation.js index 79fbc8a45c0acb..f483d0a63f3647 100644 --- a/Libraries/Animated/AnimatedImplementation.js +++ b/Libraries/Animated/AnimatedImplementation.js @@ -551,6 +551,19 @@ const event = function ( } }; +// All types of animated nodes that represent scalar numbers and can be interpolated (etc) +type AnimatedNumeric = + | AnimatedAddition + | AnimatedDiffClamp + | AnimatedDivision + | AnimatedInterpolation + | AnimatedModulo + | AnimatedMultiplication + | AnimatedSubtraction + | AnimatedValue; + +export type {AnimatedNumeric as Numeric}; + /** * The `Animated` library is designed to make animations fluid, powerful, and * easy to build and maintain. `Animated` focuses on declarative relationships diff --git a/Libraries/Animated/AnimatedMock.js b/Libraries/Animated/AnimatedMock.js index f2ce29359c2a66..af517502197d53 100644 --- a/Libraries/Animated/AnimatedMock.js +++ b/Libraries/Animated/AnimatedMock.js @@ -23,7 +23,7 @@ import type {EndCallback} from './animations/Animation'; import type {TimingAnimationConfig} from './animations/TimingAnimation'; import type {DecayAnimationConfig} from './animations/DecayAnimation'; import type {SpringAnimationConfig} from './animations/SpringAnimation'; - +import type {Numeric as AnimatedNumeric} from './AnimatedImplementation'; import AnimatedColor from './nodes/AnimatedColor'; /** @@ -163,6 +163,8 @@ const loop = function ( return emptyAnimation; }; +export type {AnimatedNumeric as Numeric}; + module.exports = { Value: AnimatedValue, ValueXY: AnimatedValueXY,