From 64720ab14a68fba7ae5ac3100499365e3c84ba85 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 28 Feb 2020 09:27:46 -0800 Subject: [PATCH] Improve typing of Animated component wrappers Summary: Provides flow-types for callers of AnimatedScrollView etc Changelog: [Internal] [Fixed] Fixed flow types of Animated components Reviewed By: cpojer Differential Revision: D20158990 fbshipit-source-id: 3d06a89086629eb9f9d2cc0f3e7a819a80456fb0 --- .../Animated/src/components/AnimatedFlatList.js | 8 ++++++-- Libraries/Animated/src/components/AnimatedImage.js | 12 ++++++++++-- .../Animated/src/components/AnimatedScrollView.js | 8 ++++++-- .../Animated/src/components/AnimatedSectionList.js | 8 ++++++-- Libraries/Animated/src/components/AnimatedText.js | 12 ++++++++++-- Libraries/Animated/src/components/AnimatedView.js | 5 ++--- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Libraries/Animated/src/components/AnimatedFlatList.js b/Libraries/Animated/src/components/AnimatedFlatList.js index a17a13e9e9..ca2922aaf4 100644 --- a/Libraries/Animated/src/components/AnimatedFlatList.js +++ b/Libraries/Animated/src/components/AnimatedFlatList.js @@ -13,9 +13,10 @@ import * as React from 'react'; const FlatList = require('../../../Lists/FlatList'); - const createAnimatedComponent = require('../createAnimatedComponent'); +import type {AnimatedComponentType} from '../createAnimatedComponent'; + /** * @see https://github.com/facebook/react-native/commit/b8c8562 */ @@ -25,4 +26,7 @@ const FlatListWithEventThrottle = React.forwardRef((props, ref) => ( module.exports = (createAnimatedComponent( FlatListWithEventThrottle, -): $FlowFixMe); +): AnimatedComponentType< + React.ElementConfig, + React.ElementRef, +>); diff --git a/Libraries/Animated/src/components/AnimatedImage.js b/Libraries/Animated/src/components/AnimatedImage.js index 89fee4d29e..f5e801845f 100644 --- a/Libraries/Animated/src/components/AnimatedImage.js +++ b/Libraries/Animated/src/components/AnimatedImage.js @@ -10,8 +10,16 @@ 'use strict'; -const Image = require('../../../Image/Image'); +import * as React from 'react'; +const Image = require('../../../Image/Image'); const createAnimatedComponent = require('../createAnimatedComponent'); -module.exports = (createAnimatedComponent(Image): $FlowFixMe); +import type {AnimatedComponentType} from '../createAnimatedComponent'; + +module.exports = (createAnimatedComponent( + (Image: $FlowFixMe), +): AnimatedComponentType< + React.ElementConfig, + React.ElementRef, +>); diff --git a/Libraries/Animated/src/components/AnimatedScrollView.js b/Libraries/Animated/src/components/AnimatedScrollView.js index 9938b59486..afed39b31c 100644 --- a/Libraries/Animated/src/components/AnimatedScrollView.js +++ b/Libraries/Animated/src/components/AnimatedScrollView.js @@ -13,9 +13,10 @@ import * as React from 'react'; const ScrollView = require('../../../Components/ScrollView/ScrollView'); - const createAnimatedComponent = require('../createAnimatedComponent'); +import type {AnimatedComponentType} from '../createAnimatedComponent'; + /** * @see https://github.com/facebook/react-native/commit/b8c8562 */ @@ -25,4 +26,7 @@ const ScrollViewWithEventThrottle = React.forwardRef((props, ref) => ( module.exports = (createAnimatedComponent( ScrollViewWithEventThrottle, -): $FlowFixMe); +): AnimatedComponentType< + React.ElementConfig, + React.ElementRef, +>); diff --git a/Libraries/Animated/src/components/AnimatedSectionList.js b/Libraries/Animated/src/components/AnimatedSectionList.js index 49e95e4adc..002f8a14c7 100644 --- a/Libraries/Animated/src/components/AnimatedSectionList.js +++ b/Libraries/Animated/src/components/AnimatedSectionList.js @@ -13,9 +13,10 @@ import * as React from 'react'; const SectionList = require('../../../Lists/SectionList'); - const createAnimatedComponent = require('../createAnimatedComponent'); +import type {AnimatedComponentType} from '../createAnimatedComponent'; + /** * @see https://github.com/facebook/react-native/commit/b8c8562 */ @@ -25,4 +26,7 @@ const SectionListWithEventThrottle = React.forwardRef((props, ref) => ( module.exports = (createAnimatedComponent( SectionListWithEventThrottle, -): $FlowFixMe); +): AnimatedComponentType< + React.ElementConfig, + React.ElementRef, +>); diff --git a/Libraries/Animated/src/components/AnimatedText.js b/Libraries/Animated/src/components/AnimatedText.js index 81b016cca1..55b8fb8c42 100644 --- a/Libraries/Animated/src/components/AnimatedText.js +++ b/Libraries/Animated/src/components/AnimatedText.js @@ -10,8 +10,16 @@ 'use strict'; -const Text = require('../../../Text/Text'); +import * as React from 'react'; +const Text = require('../../../Text/Text'); const createAnimatedComponent = require('../createAnimatedComponent'); -module.exports = (createAnimatedComponent(Text): $FlowFixMe); +import type {AnimatedComponentType} from '../createAnimatedComponent'; + +module.exports = (createAnimatedComponent( + (Text: $FlowFixMe), +): AnimatedComponentType< + React.ElementConfig, + React.ElementRef, +>); diff --git a/Libraries/Animated/src/components/AnimatedView.js b/Libraries/Animated/src/components/AnimatedView.js index 3396337eda..6e7badcced 100644 --- a/Libraries/Animated/src/components/AnimatedView.js +++ b/Libraries/Animated/src/components/AnimatedView.js @@ -10,12 +10,11 @@ 'use strict'; +import * as React from 'react'; + const View = require('../../../Components/View/View'); - const createAnimatedComponent = require('../createAnimatedComponent'); -const React = require('react'); - import type {AnimatedComponentType} from '../createAnimatedComponent'; module.exports = (createAnimatedComponent(View): AnimatedComponentType<