Skip to content

Commit f63d4e7

Browse files
gabrieldonadelfacebook-github-bot
authored andcommitted
refactor: Convert Animated directory to use ESModule imports/exports (#34539)
Summary: This PR refactors the Animated directory to use ESModule imports/exports instead of using a mixture of the 2 module formats, as requested on #34425. ## Changelog [Internal] [Changed] - Convert all files in the Animated directory to use ESModule imports/exports Pull Request resolved: #34539 Test Plan: This doesn't really add or modify any existing features so checking if CI passes should be enough Reviewed By: yungsters Differential Revision: D39235720 Pulled By: yungsters fbshipit-source-id: 84b4c0a71dc9fca1ab7053263f1cf7c336df58c1
1 parent a0d1585 commit f63d4e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+188
-229
lines changed

Libraries/Animated/Animated.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
export type {CompositeAnimation, Numeric} from './AnimatedImplementation';
12+
1113
import Platform from '../Utilities/Platform';
1214
import typeof AnimatedFlatList from './components/AnimatedFlatList';
1315
import typeof AnimatedImage from './components/AnimatedImage';
@@ -16,31 +18,31 @@ import typeof AnimatedSectionList from './components/AnimatedSectionList';
1618
import typeof AnimatedText from './components/AnimatedText';
1719
import typeof AnimatedView from './components/AnimatedView';
1820

19-
import * as AnimatedMock from './AnimatedMock';
20-
import * as AnimatedImplementation from './AnimatedImplementation';
21+
import AnimatedMock from './AnimatedMock';
22+
import AnimatedImplementation from './AnimatedImplementation';
2123

2224
const Animated = ((Platform.isTesting
2325
? AnimatedMock
24-
: AnimatedImplementation): typeof AnimatedMock);
26+
: AnimatedImplementation): typeof AnimatedImplementation);
2527

26-
module.exports = {
28+
export default {
2729
get FlatList(): AnimatedFlatList {
28-
return require('./components/AnimatedFlatList');
30+
return require('./components/AnimatedFlatList').default;
2931
},
3032
get Image(): AnimatedImage {
31-
return require('./components/AnimatedImage');
33+
return require('./components/AnimatedImage').default;
3234
},
3335
get ScrollView(): AnimatedScrollView {
34-
return require('./components/AnimatedScrollView');
36+
return require('./components/AnimatedScrollView').default;
3537
},
3638
get SectionList(): AnimatedSectionList {
37-
return require('./components/AnimatedSectionList');
39+
return require('./components/AnimatedSectionList').default;
3840
},
3941
get Text(): AnimatedText {
40-
return require('./components/AnimatedText');
42+
return require('./components/AnimatedText').default;
4143
},
4244
get View(): AnimatedView {
43-
return require('./components/AnimatedView');
45+
return require('./components/AnimatedView').default;
4446
},
4547
...Animated,
4648
};

Libraries/Animated/AnimatedEvent.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
'use strict';
1212

13-
const AnimatedValue = require('./nodes/AnimatedValue');
14-
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
15-
const NativeAnimatedHelper = require('./NativeAnimatedHelper');
16-
const {findNodeHandle} = require('../ReactNative/RendererProxy');
13+
import AnimatedValue from './nodes/AnimatedValue';
14+
import AnimatedValueXY from './nodes/AnimatedValueXY';
15+
import NativeAnimatedHelper from './NativeAnimatedHelper';
16+
import {findNodeHandle} from '../ReactNative/RendererProxy';
1717

18-
const invariant = require('invariant');
19-
20-
const {shouldUseNativeDriver} = require('./NativeAnimatedHelper');
18+
import invariant from 'invariant';
2119

2220
import type {PlatformConfig} from './AnimatedPlatformConfig';
2321

@@ -31,7 +29,7 @@ export type EventConfig = {
3129
platformConfig?: PlatformConfig,
3230
};
3331

34-
function attachNativeEvent(
32+
export function attachNativeEvent(
3533
viewRef: any,
3634
eventName: string,
3735
argMapping: $ReadOnlyArray<?Mapping>,
@@ -146,7 +144,7 @@ function validateMapping(argMapping: $ReadOnlyArray<?Mapping>, args: any) {
146144
});
147145
}
148146

149-
class AnimatedEvent {
147+
export class AnimatedEvent {
150148
_argMapping: $ReadOnlyArray<?Mapping>;
151149
_listeners: Array<Function> = [];
152150
_attachedEvent: ?{detach: () => void, ...};
@@ -165,7 +163,7 @@ class AnimatedEvent {
165163
this.__addListener(config.listener);
166164
}
167165
this._attachedEvent = null;
168-
this.__isNative = shouldUseNativeDriver(config);
166+
this.__isNative = NativeAnimatedHelper.shouldUseNativeDriver(config);
169167
this.__platformConfig = config.platformConfig;
170168
}
171169

@@ -257,5 +255,3 @@ class AnimatedEvent {
257255
this._listeners.forEach(listener => listener(...args));
258256
};
259257
}
260-
261-
module.exports = {AnimatedEvent, attachNativeEvent};

Libraries/Animated/AnimatedImplementation.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010

1111
'use strict';
1212

13-
const {AnimatedEvent, attachNativeEvent} = require('./AnimatedEvent');
14-
const AnimatedAddition = require('./nodes/AnimatedAddition');
15-
const AnimatedDiffClamp = require('./nodes/AnimatedDiffClamp');
16-
const AnimatedDivision = require('./nodes/AnimatedDivision');
17-
const AnimatedInterpolation = require('./nodes/AnimatedInterpolation');
18-
const AnimatedModulo = require('./nodes/AnimatedModulo');
19-
const AnimatedMultiplication = require('./nodes/AnimatedMultiplication');
20-
const AnimatedNode = require('./nodes/AnimatedNode');
21-
const AnimatedSubtraction = require('./nodes/AnimatedSubtraction');
22-
const AnimatedTracking = require('./nodes/AnimatedTracking');
23-
const AnimatedValue = require('./nodes/AnimatedValue');
24-
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
25-
const DecayAnimation = require('./animations/DecayAnimation');
26-
const SpringAnimation = require('./animations/SpringAnimation');
27-
const TimingAnimation = require('./animations/TimingAnimation');
28-
29-
const createAnimatedComponent = require('./createAnimatedComponent');
13+
import {AnimatedEvent, attachNativeEvent} from './AnimatedEvent';
14+
import AnimatedAddition from './nodes/AnimatedAddition';
15+
import AnimatedDiffClamp from './nodes/AnimatedDiffClamp';
16+
import AnimatedDivision from './nodes/AnimatedDivision';
17+
import AnimatedInterpolation from './nodes/AnimatedInterpolation';
18+
import AnimatedModulo from './nodes/AnimatedModulo';
19+
import AnimatedMultiplication from './nodes/AnimatedMultiplication';
20+
import AnimatedNode from './nodes/AnimatedNode';
21+
import AnimatedSubtraction from './nodes/AnimatedSubtraction';
22+
import AnimatedTracking from './nodes/AnimatedTracking';
23+
import AnimatedValue from './nodes/AnimatedValue';
24+
import AnimatedValueXY from './nodes/AnimatedValueXY';
25+
import DecayAnimation from './animations/DecayAnimation';
26+
import SpringAnimation from './animations/SpringAnimation';
27+
import TimingAnimation from './animations/TimingAnimation';
28+
29+
import createAnimatedComponent from './createAnimatedComponent';
3030

3131
import type {
3232
AnimationConfig,
@@ -575,7 +575,7 @@ export type {AnimatedNumeric as Numeric};
575575
*
576576
* See https://reactnative.dev/docs/animated
577577
*/
578-
module.exports = {
578+
export default {
579579
/**
580580
* Standard value class for driving animations. Typically initialized with
581581
* `new Animated.Value(0);`

Libraries/Animated/AnimatedMock.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
import type {EndResult} from './animations/Animation';
1414

15-
const {AnimatedEvent, attachNativeEvent} = require('./AnimatedEvent');
16-
const AnimatedImplementation = require('./AnimatedImplementation');
17-
const AnimatedInterpolation = require('./nodes/AnimatedInterpolation');
18-
const AnimatedNode = require('./nodes/AnimatedNode');
19-
const AnimatedValue = require('./nodes/AnimatedValue');
20-
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
15+
import {AnimatedEvent, attachNativeEvent} from './AnimatedEvent';
16+
import AnimatedImplementation from './AnimatedImplementation';
17+
import AnimatedInterpolation from './nodes/AnimatedInterpolation';
18+
import AnimatedNode from './nodes/AnimatedNode';
19+
import AnimatedValue from './nodes/AnimatedValue';
20+
import AnimatedValueXY from './nodes/AnimatedValueXY';
2121

22-
const createAnimatedComponent = require('./createAnimatedComponent');
22+
import createAnimatedComponent from './createAnimatedComponent';
2323

2424
import type {EndCallback} from './animations/Animation';
2525
import type {TimingAnimationConfig} from './animations/TimingAnimation';
@@ -168,7 +168,7 @@ const loop = function (
168168

169169
export type {AnimatedNumeric as Numeric};
170170

171-
module.exports = {
171+
export default {
172172
Value: AnimatedValue,
173173
ValueXY: AnimatedValueXY,
174174
Color: AnimatedColor,

Libraries/Animated/AnimatedWeb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
'use strict';
1212

13-
const AnimatedImplementation = require('./AnimatedImplementation');
13+
import AnimatedImplementation from './AnimatedImplementation';
1414

15-
module.exports = {
15+
export default {
1616
...AnimatedImplementation,
1717
/* $FlowFixMe[incompatible-call] createAnimatedComponent expects to receive
1818
* types. Plain intrinsic components can't be typed like this */

Libraries/Animated/Easing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const Easing = {
214214
x2: number,
215215
y2: number,
216216
): (t: number) => number {
217-
const _bezier = require('./bezier');
217+
const _bezier = require('./bezier').default;
218218
return _bezier(x1, y1, x2, y2);
219219
},
220220

@@ -247,4 +247,4 @@ const Easing = {
247247
},
248248
};
249249

250-
module.exports = Easing;
250+
export default Easing;

Libraries/Animated/NativeAnimatedHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ function transformDataType(value: number | string): number | string {
550550
}
551551
}
552552

553-
module.exports = {
553+
export default {
554554
API,
555555
isSupportedColorStyleProp,
556556
isSupportedStyleProp,

Libraries/Animated/SpringConfig.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function dampingFromOrigamiValue(oValue: number) {
2424
return (oValue - 8) * 3 + 25;
2525
}
2626

27-
function fromOrigamiTensionAndFriction(
27+
export function fromOrigamiTensionAndFriction(
2828
tension: number,
2929
friction: number,
3030
): SpringConfigType {
@@ -34,7 +34,7 @@ function fromOrigamiTensionAndFriction(
3434
};
3535
}
3636

37-
function fromBouncinessAndSpeed(
37+
export function fromBouncinessAndSpeed(
3838
bounciness: number,
3939
speed: number,
4040
): SpringConfigType {
@@ -96,8 +96,3 @@ function fromBouncinessAndSpeed(
9696
damping: dampingFromOrigamiValue(bouncyFriction),
9797
};
9898
}
99-
100-
module.exports = {
101-
fromOrigamiTensionAndFriction,
102-
fromBouncinessAndSpeed,
103-
};

Libraries/Animated/__tests__/Animated-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @oncall react_native
99
*/
1010

11-
import AnimatedProps from '../nodes/AnimatedProps';
1211
import TestRenderer from 'react-test-renderer';
1312
import * as React from 'react';
1413

@@ -21,7 +20,8 @@ jest.mock('../../BatchedBridge/NativeModules', () => ({
2120
},
2221
}));
2322

24-
let Animated = require('../Animated');
23+
let AnimatedProps = require('../nodes/AnimatedProps').default;
24+
let Animated = require('../Animated').default;
2525

2626
describe('Animated tests', () => {
2727
beforeEach(() => {
@@ -692,7 +692,7 @@ describe('Animated tests', () => {
692692

693693
beforeEach(() => {
694694
jest.mock('../../Interaction/InteractionManager');
695-
Animated = require('../Animated');
695+
Animated = require('../Animated').default;
696696
InteractionManager = require('../../Interaction/InteractionManager');
697697
});
698698

Libraries/Animated/__tests__/AnimatedMock-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
'use strict';
1212

13-
const AnimatedMock = require('../AnimatedMock');
14-
const AnimatedImplementation = require('../AnimatedImplementation');
13+
import AnimatedMock from '../AnimatedMock';
14+
import AnimatedImplementation from '../AnimatedImplementation';
1515

1616
describe('Animated Mock', () => {
1717
it('matches implementation keys', () => {

0 commit comments

Comments
 (0)