Skip to content

Commit a70987c

Browse files
yungstersfacebook-github-bot
authored andcommitted
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
1 parent 87e1734 commit a70987c

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

Libraries/Animated/src/components/AnimatedFlatList.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010

1111
'use strict';
1212

13+
import * as React from 'react';
14+
1315
const FlatList = require('../../../Lists/FlatList');
1416

1517
const createAnimatedComponent = require('../createAnimatedComponent');
1618

17-
module.exports = (createAnimatedComponent(FlatList, {
18-
scrollEventThrottle: 0.0001,
19-
}): $FlowFixMe);
19+
/**
20+
* @see https://github.com/facebook/react-native/commit/b8c8562
21+
*/
22+
const FlatListWithEventThrottle = React.forwardRef((props, ref) => (
23+
<FlatList scrollEventThrottle={0.0001} {...props} ref={ref} />
24+
));
25+
26+
module.exports = (createAnimatedComponent(
27+
FlatListWithEventThrottle,
28+
): $FlowFixMe);

Libraries/Animated/src/components/AnimatedScrollView.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010

1111
'use strict';
1212

13+
import * as React from 'react';
14+
1315
const ScrollView = require('../../../Components/ScrollView/ScrollView');
1416

1517
const createAnimatedComponent = require('../createAnimatedComponent');
1618

17-
module.exports = (createAnimatedComponent(ScrollView, {
18-
scrollEventThrottle: 0.0001,
19-
}): $FlowFixMe);
19+
/**
20+
* @see https://github.com/facebook/react-native/commit/b8c8562
21+
*/
22+
const ScrollViewWithEventThrottle = React.forwardRef((props, ref) => (
23+
<ScrollView scrollEventThrottle={0.0001} {...props} ref={ref} />
24+
));
25+
26+
module.exports = (createAnimatedComponent(
27+
ScrollViewWithEventThrottle,
28+
): $FlowFixMe);

Libraries/Animated/src/components/AnimatedSectionList.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010

1111
'use strict';
1212

13+
import * as React from 'react';
14+
1315
const SectionList = require('../../../Lists/SectionList');
1416

1517
const createAnimatedComponent = require('../createAnimatedComponent');
1618

17-
module.exports = (createAnimatedComponent(SectionList, {
18-
scrollEventThrottle: 0.0001,
19-
}): $FlowFixMe);
19+
/**
20+
* @see https://github.com/facebook/react-native/commit/b8c8562
21+
*/
22+
const SectionListWithEventThrottle = React.forwardRef((props, ref) => (
23+
<SectionList scrollEventThrottle={0.0001} {...props} ref={ref} />
24+
));
25+
26+
module.exports = (createAnimatedComponent(
27+
SectionListWithEventThrottle,
28+
): $FlowFixMe);

Libraries/Animated/src/createAnimatedComponent.js

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export type AnimatedComponentType<Props, Instance> = React.AbstractComponent<
2727

2828
function createAnimatedComponent<Props, Instance>(
2929
Component: React.AbstractComponent<Props, Instance>,
30-
defaultProps: any,
3130
): AnimatedComponentType<Props, Instance> {
3231
invariant(
3332
typeof Component !== 'function' ||
@@ -165,7 +164,6 @@ function createAnimatedComponent<Props, Instance>(
165164
const props = this._propsAnimated.__getValue();
166165
return (
167166
<Component
168-
{...defaultProps}
169167
{...props}
170168
ref={this._setComponentRef}
171169
// The native driver updates views directly through the UI thread so we

jest/setup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ jest
136136
'../Libraries/Animated/src/createAnimatedComponent',
137137
);
138138

139-
return (Component, defaultProps) => {
140-
const Wrapped = createAnimatedComponent(Component, defaultProps);
139+
return Component => {
140+
const Wrapped = createAnimatedComponent(Component);
141141

142142
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;
143143

0 commit comments

Comments
 (0)