Skip to content

Commit f24ae20

Browse files
refactor: Convert Animated directory to use ESModule imports/exports
1 parent df0b690 commit f24ae20

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
-231
lines changed

Libraries/Animated/Animated.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ import typeof AnimatedSectionList from './components/AnimatedSectionList';
1616
import typeof AnimatedText from './components/AnimatedText';
1717
import typeof AnimatedView from './components/AnimatedView';
1818

19-
import * as AnimatedMock from './AnimatedMock';
20-
import * as AnimatedImplementation from './AnimatedImplementation';
19+
import AnimatedMock from './AnimatedMock';
20+
import AnimatedImplementation from './AnimatedImplementation';
2121

2222
const Animated = ((Platform.isTesting
2323
? AnimatedMock
2424
: AnimatedImplementation): typeof AnimatedMock);
2525

26-
module.exports = {
26+
export default {
2727
get FlatList(): AnimatedFlatList {
28-
return require('./components/AnimatedFlatList');
28+
return require('./components/AnimatedFlatList').default;
2929
},
3030
get Image(): AnimatedImage {
31-
return require('./components/AnimatedImage');
31+
return require('./components/AnimatedImage').default;
3232
},
3333
get ScrollView(): AnimatedScrollView {
34-
return require('./components/AnimatedScrollView');
34+
return require('./components/AnimatedScrollView').default;
3535
},
3636
get SectionList(): AnimatedSectionList {
37-
return require('./components/AnimatedSectionList');
37+
return require('./components/AnimatedSectionList').default;
3838
},
3939
get Text(): AnimatedText {
40-
return require('./components/AnimatedText');
40+
return require('./components/AnimatedText').default;
4141
},
4242
get View(): AnimatedView {
43-
return require('./components/AnimatedView');
43+
return require('./components/AnimatedView').default;
4444
},
4545
...Animated,
4646
};

Libraries/Animated/AnimatedEvent.js

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

1111
'use strict';
1212

13-
const AnimatedValue = require('./nodes/AnimatedValue');
14-
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
15-
const NativeAnimatedHelper = require('./NativeAnimatedHelper');
16-
const ReactNative = require('../Renderer/shims/ReactNative');
13+
import AnimatedValue from './nodes/AnimatedValue';
14+
import AnimatedValueXY from './nodes/AnimatedValueXY';
15+
import NativeAnimatedHelper from './NativeAnimatedHelper';
16+
import ReactNative from '../Renderer/shims/ReactNative';
1717

18-
const invariant = require('invariant');
18+
import invariant from 'invariant';
1919

20-
const {shouldUseNativeDriver} = require('./NativeAnimatedHelper');
20+
import {shouldUseNativeDriver} from './NativeAnimatedHelper';
2121

2222
import type {PlatformConfig} from './AnimatedPlatformConfig';
2323

@@ -31,7 +31,7 @@ export type EventConfig = {
3131
platformConfig?: PlatformConfig,
3232
};
3333

34-
function attachNativeEvent(
34+
export function attachNativeEvent(
3535
viewRef: any,
3636
eventName: string,
3737
argMapping: $ReadOnlyArray<?Mapping>,
@@ -146,7 +146,7 @@ function validateMapping(argMapping: $ReadOnlyArray<?Mapping>, args: any) {
146146
});
147147
}
148148

149-
class AnimatedEvent {
149+
export class AnimatedEvent {
150150
_argMapping: $ReadOnlyArray<?Mapping>;
151151
_listeners: Array<Function> = [];
152152
_attachedEvent: ?{detach: () => void, ...};
@@ -257,5 +257,3 @@ class AnimatedEvent {
257257
this._listeners.forEach(listener => listener(...args));
258258
};
259259
}
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: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const nativeOps: ?typeof NativeAnimatedModule = useSingleOpBatching
9191
* Wrappers around NativeAnimatedModule to provide flow and autocomplete support for
9292
* the native module methods, and automatic queue management on Android
9393
*/
94-
const API = {
94+
export const API = {
9595
getValue: function (
9696
tag: number,
9797
saveValueCallback: (value: number) => void,
@@ -419,35 +419,35 @@ const SUPPORTED_INTERPOLATION_PARAMS = {
419419
extrapolateLeft: true,
420420
};
421421

422-
function addWhitelistedStyleProp(prop: string): void {
422+
export function addWhitelistedStyleProp(prop: string): void {
423423
SUPPORTED_STYLES[prop] = true;
424424
}
425425

426-
function addWhitelistedTransformProp(prop: string): void {
426+
export function addWhitelistedTransformProp(prop: string): void {
427427
SUPPORTED_TRANSFORMS[prop] = true;
428428
}
429429

430-
function addWhitelistedInterpolationParam(param: string): void {
430+
export function addWhitelistedInterpolationParam(param: string): void {
431431
SUPPORTED_INTERPOLATION_PARAMS[param] = true;
432432
}
433433

434-
function isSupportedColorStyleProp(prop: string): boolean {
434+
export function isSupportedColorStyleProp(prop: string): boolean {
435435
return SUPPORTED_COLOR_STYLES.hasOwnProperty(prop);
436436
}
437437

438-
function isSupportedStyleProp(prop: string): boolean {
438+
export function isSupportedStyleProp(prop: string): boolean {
439439
return SUPPORTED_STYLES.hasOwnProperty(prop);
440440
}
441441

442-
function isSupportedTransformProp(prop: string): boolean {
442+
export function isSupportedTransformProp(prop: string): boolean {
443443
return SUPPORTED_TRANSFORMS.hasOwnProperty(prop);
444444
}
445445

446-
function isSupportedInterpolationParam(param: string): boolean {
446+
export function isSupportedInterpolationParam(param: string): boolean {
447447
return SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(param);
448448
}
449449

450-
function validateTransform(
450+
export function validateTransform(
451451
configs: Array<
452452
| {
453453
type: 'animated',
@@ -472,7 +472,7 @@ function validateTransform(
472472
});
473473
}
474474

475-
function validateStyles(styles: {[key: string]: ?number, ...}): void {
475+
export function validateStyles(styles: {[key: string]: ?number, ...}): void {
476476
for (const key in styles) {
477477
if (!isSupportedStyleProp(key)) {
478478
throw new Error(
@@ -482,7 +482,7 @@ function validateStyles(styles: {[key: string]: ?number, ...}): void {
482482
}
483483
}
484484

485-
function validateInterpolation<OutputT: number | string>(
485+
export function validateInterpolation<OutputT: number | string>(
486486
config: InterpolationConfigType<OutputT>,
487487
): void {
488488
for (const key in config) {
@@ -494,21 +494,21 @@ function validateInterpolation<OutputT: number | string>(
494494
}
495495
}
496496

497-
function generateNewNodeTag(): number {
497+
export function generateNewNodeTag(): number {
498498
return __nativeAnimatedNodeTagCount++;
499499
}
500500

501-
function generateNewAnimationId(): number {
501+
export function generateNewAnimationId(): number {
502502
return __nativeAnimationIdCount++;
503503
}
504504

505-
function assertNativeAnimatedModule(): void {
505+
export function assertNativeAnimatedModule(): void {
506506
invariant(NativeAnimatedModule, 'Native animated module is not available');
507507
}
508508

509509
let _warnedMissingNativeAnimated = false;
510510

511-
function shouldUseNativeDriver(
511+
export function shouldUseNativeDriver(
512512
config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
513513
): boolean {
514514
if (config.useNativeDriver == null) {
@@ -535,7 +535,7 @@ function shouldUseNativeDriver(
535535
return config.useNativeDriver || false;
536536
}
537537

538-
function transformDataType(value: number | string): number | string {
538+
export function transformDataType(value: number | string): number | string {
539539
// Change the string type to number type so we can reuse the same logic in
540540
// iOS and Android platform
541541
if (typeof value !== 'string') {
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jest.mock('../../BatchedBridge/NativeModules', () => ({
2121
},
2222
}));
2323

24-
let Animated = require('../Animated');
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)