Skip to content

Commit

Permalink
refactor: Convert Animated directory to use ESModule imports/exports
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Aug 31, 2022
1 parent df0b690 commit f24ae20
Show file tree
Hide file tree
Showing 44 changed files with 188 additions and 231 deletions.
18 changes: 9 additions & 9 deletions Libraries/Animated/Animated.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,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);

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,
};
18 changes: 8 additions & 10 deletions Libraries/Animated/AnimatedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

'use strict';

const AnimatedValue = require('./nodes/AnimatedValue');
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
const NativeAnimatedHelper = require('./NativeAnimatedHelper');
const ReactNative = require('../Renderer/shims/ReactNative');
import AnimatedValue from './nodes/AnimatedValue';
import AnimatedValueXY from './nodes/AnimatedValueXY';
import NativeAnimatedHelper from './NativeAnimatedHelper';
import ReactNative from '../Renderer/shims/ReactNative';

const invariant = require('invariant');
import invariant from 'invariant';

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

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

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

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

class AnimatedEvent {
export class AnimatedEvent {
_argMapping: $ReadOnlyArray<?Mapping>;
_listeners: Array<Function> = [];
_attachedEvent: ?{detach: () => void, ...};
Expand Down Expand Up @@ -257,5 +257,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;
34 changes: 17 additions & 17 deletions Libraries/Animated/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const nativeOps: ?typeof NativeAnimatedModule = useSingleOpBatching
* Wrappers around NativeAnimatedModule to provide flow and autocomplete support for
* the native module methods, and automatic queue management on Android
*/
const API = {
export const API = {
getValue: function (
tag: number,
saveValueCallback: (value: number) => void,
Expand Down Expand Up @@ -419,35 +419,35 @@ const SUPPORTED_INTERPOLATION_PARAMS = {
extrapolateLeft: true,
};

function addWhitelistedStyleProp(prop: string): void {
export function addWhitelistedStyleProp(prop: string): void {
SUPPORTED_STYLES[prop] = true;
}

function addWhitelistedTransformProp(prop: string): void {
export function addWhitelistedTransformProp(prop: string): void {
SUPPORTED_TRANSFORMS[prop] = true;
}

function addWhitelistedInterpolationParam(param: string): void {
export function addWhitelistedInterpolationParam(param: string): void {
SUPPORTED_INTERPOLATION_PARAMS[param] = true;
}

function isSupportedColorStyleProp(prop: string): boolean {
export function isSupportedColorStyleProp(prop: string): boolean {
return SUPPORTED_COLOR_STYLES.hasOwnProperty(prop);
}

function isSupportedStyleProp(prop: string): boolean {
export function isSupportedStyleProp(prop: string): boolean {
return SUPPORTED_STYLES.hasOwnProperty(prop);
}

function isSupportedTransformProp(prop: string): boolean {
export function isSupportedTransformProp(prop: string): boolean {
return SUPPORTED_TRANSFORMS.hasOwnProperty(prop);
}

function isSupportedInterpolationParam(param: string): boolean {
export function isSupportedInterpolationParam(param: string): boolean {
return SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(param);
}

function validateTransform(
export function validateTransform(
configs: Array<
| {
type: 'animated',
Expand All @@ -472,7 +472,7 @@ function validateTransform(
});
}

function validateStyles(styles: {[key: string]: ?number, ...}): void {
export function validateStyles(styles: {[key: string]: ?number, ...}): void {
for (const key in styles) {
if (!isSupportedStyleProp(key)) {
throw new Error(
Expand All @@ -482,7 +482,7 @@ function validateStyles(styles: {[key: string]: ?number, ...}): void {
}
}

function validateInterpolation<OutputT: number | string>(
export function validateInterpolation<OutputT: number | string>(
config: InterpolationConfigType<OutputT>,
): void {
for (const key in config) {
Expand All @@ -494,21 +494,21 @@ function validateInterpolation<OutputT: number | string>(
}
}

function generateNewNodeTag(): number {
export function generateNewNodeTag(): number {
return __nativeAnimatedNodeTagCount++;
}

function generateNewAnimationId(): number {
export function generateNewAnimationId(): number {
return __nativeAnimationIdCount++;
}

function assertNativeAnimatedModule(): void {
export function assertNativeAnimatedModule(): void {
invariant(NativeAnimatedModule, 'Native animated module is not available');
}

let _warnedMissingNativeAnimated = false;

function shouldUseNativeDriver(
export function shouldUseNativeDriver(
config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
): boolean {
if (config.useNativeDriver == null) {
Expand All @@ -535,7 +535,7 @@ function shouldUseNativeDriver(
return config.useNativeDriver || false;
}

function transformDataType(value: number | string): number | string {
export function transformDataType(value: number | string): number | string {
// Change the string type to number type so we can reuse the same logic in
// iOS and Android platform
if (typeof value !== 'string') {
Expand All @@ -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,
};
4 changes: 2 additions & 2 deletions Libraries/Animated/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock('../../BatchedBridge/NativeModules', () => ({
},
}));

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

0 comments on commit f24ae20

Please sign in to comment.