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:57:59 -08:00 коммит произвёл Facebook Github Bot
Родитель 87e1734217
Коммит a70987cee2
5 изменённых файлов: 38 добавлений и 13 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;