Skip to content

Commit b8c8562

Browse files
sahrensfacebook-github-bot
authored andcommitted
Set scroll view throttle by default
Summary: Setting the scroll throttle for every animated scrollview is a pain, and if you forget it's super janky and can be confusing and frustrating. Enables setting default props in createAnimatedComponent and uses it for scrollview. Reviewed By: TheSavior Differential Revision: D14790093 fbshipit-source-id: dd8f6f6540813245e87d696351f09ebb2e6ed5f2
1 parent 929087b commit b8c8562

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

Libraries/Animated/src/__tests__/AnimatedMock-test.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,34 @@ describe('Animated Mock', () => {
1919
Object.keys(AnimatedImplementation),
2020
);
2121
});
22-
it('matches implementation params', () => {
23-
Object.keys(AnimatedImplementation).forEach(key =>
24-
expect(AnimatedImplementation[key].length).toEqual(
25-
AnimatedMock[key].length,
26-
),
27-
);
22+
it('matches implementation params', done => {
23+
Object.keys(AnimatedImplementation).forEach(key => {
24+
if (AnimatedImplementation[key].length !== AnimatedMock[key].length) {
25+
done(
26+
new Error(
27+
'key ' +
28+
key +
29+
' had different lengths: ' +
30+
JSON.stringify(
31+
{
32+
impl: {
33+
len: AnimatedImplementation[key].length,
34+
type: typeof AnimatedImplementation[key],
35+
val: AnimatedImplementation[key].toString(),
36+
},
37+
mock: {
38+
len: AnimatedMock[key].length,
39+
type: typeof AnimatedMock[key],
40+
val: AnimatedMock[key].toString(),
41+
},
42+
},
43+
null,
44+
2,
45+
),
46+
),
47+
);
48+
}
49+
});
50+
done();
2851
});
2952
});

Libraries/Animated/src/components/AnimatedScrollView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const ScrollView = require('ScrollView');
1414

1515
const createAnimatedComponent = require('createAnimatedComponent');
1616

17-
module.exports = createAnimatedComponent(ScrollView);
17+
module.exports = createAnimatedComponent(ScrollView, {scrollEventThrottle: 16});

Libraries/Animated/src/createAnimatedComponent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const DeprecatedViewStylePropTypes = require('DeprecatedViewStylePropTypes');
1616

1717
const invariant = require('invariant');
1818

19-
function createAnimatedComponent(Component: any): any {
19+
function createAnimatedComponent(Component: any, defaultProps: any): any {
2020
invariant(
2121
typeof Component !== 'function' ||
2222
(Component.prototype && Component.prototype.isReactComponent),
@@ -149,6 +149,7 @@ function createAnimatedComponent(Component: any): any {
149149
const props = this._propsAnimated.__getValue();
150150
return (
151151
<Component
152+
{...defaultProps}
152153
{...props}
153154
ref={this._setComponentRef}
154155
// The native driver updates views directly through the UI thread so we

jest/setup.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ jest
4545
.mock('AnimatedImplementation', () => {
4646
const AnimatedImplementation = jest.requireActual('AnimatedImplementation');
4747
const oldCreate = AnimatedImplementation.createAnimatedComponent;
48-
AnimatedImplementation.createAnimatedComponent = function(Component) {
49-
const Wrapped = oldCreate(Component);
48+
AnimatedImplementation.createAnimatedComponent = function(
49+
Component,
50+
defaultProps,
51+
) {
52+
const Wrapped = oldCreate(Component, defaultProps);
5053
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;
5154
return Wrapped;
5255
};

0 commit comments

Comments
 (0)