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
This commit is contained in:
Tim Yung
2019-11-03 11:59:52 -08:00
committed by Facebook Github Bot
parent 87e1734217
commit a70987cee2
5 changed files with 38 additions and 13 deletions
@@ -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) => (
<FlatList scrollEventThrottle={0.0001} {...props} ref={ref} />
));
module.exports = (createAnimatedComponent(
FlatListWithEventThrottle,
): $FlowFixMe);
@@ -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) => (
<ScrollView scrollEventThrottle={0.0001} {...props} ref={ref} />
));
module.exports = (createAnimatedComponent(
ScrollViewWithEventThrottle,
): $FlowFixMe);
@@ -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) => (
<SectionList scrollEventThrottle={0.0001} {...props} ref={ref} />
));
module.exports = (createAnimatedComponent(
SectionListWithEventThrottle,
): $FlowFixMe);
@@ -27,7 +27,6 @@ export type AnimatedComponentType<Props, Instance> = React.AbstractComponent<
function createAnimatedComponent<Props, Instance>(
Component: React.AbstractComponent<Props, Instance>,
defaultProps: any,
): AnimatedComponentType<Props, Instance> {
invariant(
typeof Component !== 'function' ||
@@ -165,7 +164,6 @@ function createAnimatedComponent<Props, Instance>(
const props = this._propsAnimated.__getValue();
return (
<Component
{...defaultProps}
{...props}
ref={this._setComponentRef}
// The native driver updates views directly through the UI thread so we
+2 -2
View File
@@ -136,8 +136,8 @@ jest
'../Libraries/Animated/src/createAnimatedComponent',
);
return (Component, defaultProps) => {
const Wrapped = createAnimatedComponent(Component, defaultProps);
return Component => {
const Wrapped = createAnimatedComponent(Component);
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;