From a70987cee24bcd027b9c4a5aa85dfd6a1aab74b3 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Sun, 3 Nov 2019 11:57:59 -0800 Subject: [PATCH] Animated: Remove `defaultProps` Parameter Summary: Simplifies `Animated` by removing `defaultProps` in favor of composition and a more isolated fix for scroll components. Changelog: [Breaking] Removed second defaultProps argument from createAnimatedComponent. Reviewed By: TheSavior Differential Revision: D18289648 fbshipit-source-id: 4e91c34297c3231f2bf691da74a7a624ca0b4f29 --- .../Animated/src/components/AnimatedFlatList.js | 15 ++++++++++++--- .../Animated/src/components/AnimatedScrollView.js | 15 ++++++++++++--- .../src/components/AnimatedSectionList.js | 15 ++++++++++++--- Libraries/Animated/src/createAnimatedComponent.js | 2 -- jest/setup.js | 4 ++-- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/Libraries/Animated/src/components/AnimatedFlatList.js b/Libraries/Animated/src/components/AnimatedFlatList.js index 2cc3704df4f..a17a13e9e9f 100644 --- a/Libraries/Animated/src/components/AnimatedFlatList.js +++ b/Libraries/Animated/src/components/AnimatedFlatList.js @@ -10,10 +10,19 @@ 'use strict'; +import * as React from 'react'; + const FlatList = require('../../../Lists/FlatList'); const createAnimatedComponent = require('../createAnimatedComponent'); -module.exports = (createAnimatedComponent(FlatList, { - scrollEventThrottle: 0.0001, -}): $FlowFixMe); +/** + * @see https://github.com/facebook/react-native/commit/b8c8562 + */ +const FlatListWithEventThrottle = React.forwardRef((props, ref) => ( + +)); + +module.exports = (createAnimatedComponent( + FlatListWithEventThrottle, +): $FlowFixMe); diff --git a/Libraries/Animated/src/components/AnimatedScrollView.js b/Libraries/Animated/src/components/AnimatedScrollView.js index 5913fb939a1..9938b594868 100644 --- a/Libraries/Animated/src/components/AnimatedScrollView.js +++ b/Libraries/Animated/src/components/AnimatedScrollView.js @@ -10,10 +10,19 @@ 'use strict'; +import * as React from 'react'; + const ScrollView = require('../../../Components/ScrollView/ScrollView'); const createAnimatedComponent = require('../createAnimatedComponent'); -module.exports = (createAnimatedComponent(ScrollView, { - scrollEventThrottle: 0.0001, -}): $FlowFixMe); +/** + * @see https://github.com/facebook/react-native/commit/b8c8562 + */ +const ScrollViewWithEventThrottle = React.forwardRef((props, ref) => ( + +)); + +module.exports = (createAnimatedComponent( + ScrollViewWithEventThrottle, +): $FlowFixMe); diff --git a/Libraries/Animated/src/components/AnimatedSectionList.js b/Libraries/Animated/src/components/AnimatedSectionList.js index 6a4a6389fbf..49e95e4adc7 100644 --- a/Libraries/Animated/src/components/AnimatedSectionList.js +++ b/Libraries/Animated/src/components/AnimatedSectionList.js @@ -10,10 +10,19 @@ 'use strict'; +import * as React from 'react'; + const SectionList = require('../../../Lists/SectionList'); const createAnimatedComponent = require('../createAnimatedComponent'); -module.exports = (createAnimatedComponent(SectionList, { - scrollEventThrottle: 0.0001, -}): $FlowFixMe); +/** + * @see https://github.com/facebook/react-native/commit/b8c8562 + */ +const SectionListWithEventThrottle = React.forwardRef((props, ref) => ( + +)); + +module.exports = (createAnimatedComponent( + SectionListWithEventThrottle, +): $FlowFixMe); diff --git a/Libraries/Animated/src/createAnimatedComponent.js b/Libraries/Animated/src/createAnimatedComponent.js index 6b4c3e056e2..d4facbb19c3 100644 --- a/Libraries/Animated/src/createAnimatedComponent.js +++ b/Libraries/Animated/src/createAnimatedComponent.js @@ -27,7 +27,6 @@ export type AnimatedComponentType = React.AbstractComponent< function createAnimatedComponent( Component: React.AbstractComponent, - defaultProps: any, ): AnimatedComponentType { invariant( typeof Component !== 'function' || @@ -165,7 +164,6 @@ function createAnimatedComponent( const props = this._propsAnimated.__getValue(); return ( { - const Wrapped = createAnimatedComponent(Component, defaultProps); + return Component => { + const Wrapped = createAnimatedComponent(Component); Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;