Skip to content

Commit

Permalink
refactor: Convert Animated directory to use ESModule imports/exports (f…
Browse files Browse the repository at this point in the history
…acebook#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 facebook#34425.

## Changelog

[Internal] [Changed] - Convert all files in the Animated directory to use ESModule imports/exports

Pull Request resolved: facebook#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
  • Loading branch information
gabrieldonadel authored and OlimpiaZurek committed May 22, 2023
1 parent a81b9b3 commit a5631c8
Show file tree
Hide file tree
Showing 44 changed files with 188 additions and 229 deletions.
22 changes: 12 additions & 10 deletions Libraries/Animated/Animated.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @format
*/

export type {CompositeAnimation, Numeric} from './AnimatedImplementation';

import Platform from '../Utilities/Platform';
import typeof AnimatedFlatList from './components/AnimatedFlatList';
import typeof AnimatedImage from './components/AnimatedImage';
Expand All @@ -16,31 +18,31 @@ import typeof AnimatedSectionList from './components/AnimatedSectionList';
import typeof AnimatedText from './components/AnimatedText';
import typeof AnimatedView from './components/AnimatedView';

import * as AnimatedMock from './AnimatedMock';
import * as AnimatedImplementation from './AnimatedImplementation';
import AnimatedMock from './AnimatedMock';
import AnimatedImplementation from './AnimatedImplementation';

const Animated = ((Platform.isTesting
? AnimatedMock
: AnimatedImplementation): typeof AnimatedMock);
: AnimatedImplementation): typeof AnimatedImplementation);

module.exports = {
export default {
get FlatList(): AnimatedFlatList {
return require('./components/AnimatedFlatList');
return require('./components/AnimatedFlatList').default;
},
get Image(): AnimatedImage {
return require('./components/AnimatedImage');
return require('./components/AnimatedImage').default;
},
get ScrollView(): AnimatedScrollView {
return require('./components/AnimatedScrollView');
return require('./components/AnimatedScrollView').default;
},
get SectionList(): AnimatedSectionList {
return require('./components/AnimatedSectionList');
return require('./components/AnimatedSectionList').default;
},
get Text(): AnimatedText {
return require('./components/AnimatedText');
return require('./components/AnimatedText').default;
},
get View(): AnimatedView {
return require('./components/AnimatedView');
return require('./components/AnimatedView').default;
},
...Animated,
};
20 changes: 8 additions & 12 deletions Libraries/Animated/AnimatedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

'use strict';

const AnimatedValue = require('./nodes/AnimatedValue');
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
const NativeAnimatedHelper = require('./NativeAnimatedHelper');
const {findNodeHandle} = require('../ReactNative/RendererProxy');
import AnimatedValue from './nodes/AnimatedValue';
import AnimatedValueXY from './nodes/AnimatedValueXY';
import NativeAnimatedHelper from './NativeAnimatedHelper';
import {findNodeHandle} from '../ReactNative/RendererProxy';

const invariant = require('invariant');

const {shouldUseNativeDriver} = require('./NativeAnimatedHelper');
import invariant from 'invariant';

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

Expand All @@ -31,7 +29,7 @@ export type EventConfig = {
platformConfig?: PlatformConfig,
};

function attachNativeEvent(
export function attachNativeEvent(
viewRef: any,
eventName: string,
argMapping: $ReadOnlyArray<?Mapping>,
Expand Down Expand Up @@ -146,7 +144,7 @@ function validateMapping(argMapping: $ReadOnlyArray<?Mapping>, args: any) {
});
}

class AnimatedEvent {
export class AnimatedEvent {
_argMapping: $ReadOnlyArray<?Mapping>;
_listeners: Array<Function> = [];
_attachedEvent: ?{detach: () => void, ...};
Expand All @@ -165,7 +163,7 @@ class AnimatedEvent {
this.__addListener(config.listener);
}
this._attachedEvent = null;
this.__isNative = shouldUseNativeDriver(config);
this.__isNative = NativeAnimatedHelper.shouldUseNativeDriver(config);
this.__platformConfig = config.platformConfig;
}

Expand Down Expand Up @@ -257,5 +255,3 @@ class AnimatedEvent {
this._listeners.forEach(listener => listener(...args));
};
}

module.exports = {AnimatedEvent, attachNativeEvent};
36 changes: 18 additions & 18 deletions Libraries/Animated/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

'use strict';

const {AnimatedEvent, attachNativeEvent} = require('./AnimatedEvent');
const AnimatedAddition = require('./nodes/AnimatedAddition');
const AnimatedDiffClamp = require('./nodes/AnimatedDiffClamp');
const AnimatedDivision = require('./nodes/AnimatedDivision');
const AnimatedInterpolation = require('./nodes/AnimatedInterpolation');
const AnimatedModulo = require('./nodes/AnimatedModulo');
const AnimatedMultiplication = require('./nodes/AnimatedMultiplication');
const AnimatedNode = require('./nodes/AnimatedNode');
const AnimatedSubtraction = require('./nodes/AnimatedSubtraction');
const AnimatedTracking = require('./nodes/AnimatedTracking');
const AnimatedValue = require('./nodes/AnimatedValue');
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
const DecayAnimation = require('./animations/DecayAnimation');
const SpringAnimation = require('./animations/SpringAnimation');
const TimingAnimation = require('./animations/TimingAnimation');

const createAnimatedComponent = require('./createAnimatedComponent');
import {AnimatedEvent, attachNativeEvent} from './AnimatedEvent';
import AnimatedAddition from './nodes/AnimatedAddition';
import AnimatedDiffClamp from './nodes/AnimatedDiffClamp';
import AnimatedDivision from './nodes/AnimatedDivision';
import AnimatedInterpolation from './nodes/AnimatedInterpolation';
import AnimatedModulo from './nodes/AnimatedModulo';
import AnimatedMultiplication from './nodes/AnimatedMultiplication';
import AnimatedNode from './nodes/AnimatedNode';
import AnimatedSubtraction from './nodes/AnimatedSubtraction';
import AnimatedTracking from './nodes/AnimatedTracking';
import AnimatedValue from './nodes/AnimatedValue';
import AnimatedValueXY from './nodes/AnimatedValueXY';
import DecayAnimation from './animations/DecayAnimation';
import SpringAnimation from './animations/SpringAnimation';
import TimingAnimation from './animations/TimingAnimation';

import createAnimatedComponent from './createAnimatedComponent';

import type {
AnimationConfig,
Expand Down Expand Up @@ -575,7 +575,7 @@ export type {AnimatedNumeric as Numeric};
*
* See https://reactnative.dev/docs/animated
*/
module.exports = {
export default {
/**
* Standard value class for driving animations. Typically initialized with
* `new Animated.Value(0);`
Expand Down
16 changes: 8 additions & 8 deletions Libraries/Animated/AnimatedMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

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

const {AnimatedEvent, attachNativeEvent} = require('./AnimatedEvent');
const AnimatedImplementation = require('./AnimatedImplementation');
const AnimatedInterpolation = require('./nodes/AnimatedInterpolation');
const AnimatedNode = require('./nodes/AnimatedNode');
const AnimatedValue = require('./nodes/AnimatedValue');
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
import {AnimatedEvent, attachNativeEvent} from './AnimatedEvent';
import AnimatedImplementation from './AnimatedImplementation';
import AnimatedInterpolation from './nodes/AnimatedInterpolation';
import AnimatedNode from './nodes/AnimatedNode';
import AnimatedValue from './nodes/AnimatedValue';
import AnimatedValueXY from './nodes/AnimatedValueXY';

const createAnimatedComponent = require('./createAnimatedComponent');
import createAnimatedComponent from './createAnimatedComponent';

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

export type {AnimatedNumeric as Numeric};

module.exports = {
export default {
Value: AnimatedValue,
ValueXY: AnimatedValueXY,
Color: AnimatedColor,
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/AnimatedWeb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

'use strict';

const AnimatedImplementation = require('./AnimatedImplementation');
import AnimatedImplementation from './AnimatedImplementation';

module.exports = {
export default {
...AnimatedImplementation,
/* $FlowFixMe[incompatible-call] createAnimatedComponent expects to receive
* types. Plain intrinsic components can't be typed like this */
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/Easing.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const Easing = {
x2: number,
y2: number,
): (t: number) => number {
const _bezier = require('./bezier');
const _bezier = require('./bezier').default;
return _bezier(x1, y1, x2, y2);
},

Expand Down Expand Up @@ -247,4 +247,4 @@ const Easing = {
},
};

module.exports = Easing;
export default Easing;
2 changes: 1 addition & 1 deletion Libraries/Animated/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ function transformDataType(value: number | string): number | string {
}
}

module.exports = {
export default {
API,
isSupportedColorStyleProp,
isSupportedStyleProp,
Expand Down
9 changes: 2 additions & 7 deletions Libraries/Animated/SpringConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function dampingFromOrigamiValue(oValue: number) {
return (oValue - 8) * 3 + 25;
}

function fromOrigamiTensionAndFriction(
export function fromOrigamiTensionAndFriction(
tension: number,
friction: number,
): SpringConfigType {
Expand All @@ -34,7 +34,7 @@ function fromOrigamiTensionAndFriction(
};
}

function fromBouncinessAndSpeed(
export function fromBouncinessAndSpeed(
bounciness: number,
speed: number,
): SpringConfigType {
Expand Down Expand Up @@ -96,8 +96,3 @@ function fromBouncinessAndSpeed(
damping: dampingFromOrigamiValue(bouncyFriction),
};
}

module.exports = {
fromOrigamiTensionAndFriction,
fromBouncinessAndSpeed,
};
6 changes: 3 additions & 3 deletions Libraries/Animated/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @oncall react_native
*/

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

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

let Animated = require('../Animated');
let AnimatedProps = require('../nodes/AnimatedProps').default;
let Animated = require('../Animated').default;

describe('Animated tests', () => {
beforeEach(() => {
Expand Down Expand Up @@ -692,7 +692,7 @@ describe('Animated tests', () => {

beforeEach(() => {
jest.mock('../../Interaction/InteractionManager');
Animated = require('../Animated');
Animated = require('../Animated').default;
InteractionManager = require('../../Interaction/InteractionManager');
});

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/__tests__/AnimatedMock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

'use strict';

const AnimatedMock = require('../AnimatedMock');
const AnimatedImplementation = require('../AnimatedImplementation');
import AnimatedMock from '../AnimatedMock';
import AnimatedImplementation from '../AnimatedImplementation';

describe('Animated Mock', () => {
it('matches implementation keys', () => {
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/__tests__/AnimatedNative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jest
import TestRenderer from 'react-test-renderer';
import * as React from 'react';

const Animated = require('../Animated');
const NativeAnimatedHelper = require('../NativeAnimatedHelper');
const Animated = require('../Animated').default;
const NativeAnimatedHelper = require('../NativeAnimatedHelper').default;

describe('Native Animated', () => {
const NativeAnimatedModule = require('../NativeAnimatedModule').default;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/__tests__/Easing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const Easing = require('../Easing');
import Easing from '../Easing';
describe('Easing', () => {
it('should work with linear', () => {
const easing = Easing.linear;
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Animated/__tests__/Interpolation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

'use strict';

const AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
const Easing = require('../Easing');
import AnimatedInterpolation from '../nodes/AnimatedInterpolation';
import Easing from '../Easing';

describe('Interpolation', () => {
it('should work with defaults', () => {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/__tests__/TimingAnimation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const TimingAnimation = require('../animations/TimingAnimation');
import TimingAnimation from '../animations/TimingAnimation';

describe('Timing Animation', () => {
it('should return array of 61 items', () => {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/__tests__/bezier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

const bezier = require('../bezier');
import bezier from '../bezier';

const identity = function (x: number) {
return x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

'use strict';

const createAnimatedComponent = require('../createAnimatedComponent');
const createAnimatedComponent = require('../createAnimatedComponent').default;
const createAnimatedComponentInjection = require('../createAnimatedComponentInjection');
const React = require('react');
import * as React from 'react';

function injected<TProps: {...}, TInstance>(
Component: React.AbstractComponent<TProps, TInstance>,
Expand Down
6 changes: 2 additions & 4 deletions Libraries/Animated/animations/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const NativeAnimatedHelper = require('../NativeAnimatedHelper');
import NativeAnimatedHelper from '../NativeAnimatedHelper';
import type {PlatformConfig} from '../AnimatedPlatformConfig';
import type AnimatedValue from '../nodes/AnimatedValue';

Expand All @@ -30,7 +30,7 @@ let startNativeAnimationNextId = 1;
// Important note: start() and stop() will only be called at most once.
// Once an animation has been stopped or finished its course, it will
// not be reused.
class Animation {
export default class Animation {
__active: boolean;
__isInteraction: boolean;
__nativeId: number;
Expand Down Expand Up @@ -85,5 +85,3 @@ class Animation {
}
}
}

module.exports = Animation;
Loading

0 comments on commit a5631c8

Please sign in to comment.