Skip to content
Permalink
Browse files
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 3, 2019
1 parent 87e1734 commit a70987cee24bcd027b9c4a5aa85dfd6a1aab74b3
Show file tree
Hide file tree
Showing 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
@@ -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;

0 comments on commit a70987c

Please sign in to comment.