Skip to content

Commit

Permalink
Animated: Remove defaultProps Parameter
Browse files Browse the repository at this point in the history
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 a70987c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
15 changes: 12 additions & 3 deletions Libraries/Animated/src/components/AnimatedFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 12 additions & 3 deletions Libraries/Animated/src/components/AnimatedScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 12 additions & 3 deletions Libraries/Animated/src/components/AnimatedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 0 additions & 2 deletions Libraries/Animated/src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a70987c

Please sign in to comment.