From bdf06288b06159e438d478b049ed01a410d9c016 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Mon, 17 Feb 2025 06:02:19 -0800 Subject: [PATCH] Align LayoutAnimation types with OSS Summary: Changelog: [Internal] Differential Revision: D69745571 --- .../LayoutAnimation/LayoutAnimation.js | 22 +++++++++++++++---- .../__snapshots__/public-api-test.js.snap | 21 +++++++++++++----- scripts/build/build-types/buildTypes.js | 1 + 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js b/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js index 7078d533e7ad..1f1bf62174c7 100644 --- a/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js @@ -20,11 +20,25 @@ import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNa import {getFabricUIManager} from '../ReactNative/FabricUIManager'; import Platform from '../Utilities/Platform'; +export type { + LayoutAnimationType, + LayoutAnimationProperty, + LayoutAnimationAnimationConfig as LayoutAnimationAnim, +} from '../Renderer/shims/ReactNativeTypes'; + const UIManager = require('../ReactNative/UIManager').default; // Reexport type export type LayoutAnimationConfig = LayoutAnimationConfig_; +export type LayoutAnimationTypes = $ReadOnly<{ + [type in LayoutAnimationType]: type, +}>; + +export type LayoutAnimationProperties = $ReadOnly<{ + [prop in LayoutAnimationProperty]: prop, +}>; + type OnAnimationDidEndCallback = () => void; type OnAnimationDidFailCallback = () => void; @@ -103,8 +117,8 @@ function configureNext( function create( duration: number, - type: LayoutAnimationType, - property: LayoutAnimationProperty, + type?: LayoutAnimationType, + property?: LayoutAnimationProperty, ): LayoutAnimationConfig { return { duration, @@ -174,13 +188,13 @@ const LayoutAnimation = { easeIn: 'easeIn', easeOut: 'easeOut', keyboard: 'keyboard', - }) as $ReadOnly<{[K in LayoutAnimationType]: K}>, + }) as LayoutAnimationTypes, Properties: Object.freeze({ opacity: 'opacity', scaleX: 'scaleX', scaleY: 'scaleY', scaleXY: 'scaleXY', - }) as $ReadOnly<{[K in LayoutAnimationProperty]: K}>, + }) as LayoutAnimationProperties, checkConfig(...args: Array) { console.error('LayoutAnimation.checkConfig(...) has been disabled.'); }, diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 190e13833f48..53d437b7f8cf 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -4921,7 +4921,18 @@ declare export default typeof TouchHistoryMath; `; exports[`public API should not change unintentionally Libraries/LayoutAnimation/LayoutAnimation.js 1`] = ` -"export type LayoutAnimationConfig = LayoutAnimationConfig_; +"export type { + LayoutAnimationType, + LayoutAnimationProperty, + LayoutAnimationAnimationConfig as LayoutAnimationAnim, +} from \\"../Renderer/shims/ReactNativeTypes\\"; +export type LayoutAnimationConfig = LayoutAnimationConfig_; +export type LayoutAnimationTypes = $ReadOnly<{ + [type in LayoutAnimationType]: type, +}>; +export type LayoutAnimationProperties = $ReadOnly<{ + [prop in LayoutAnimationProperty]: prop, +}>; type OnAnimationDidEndCallback = () => void; type OnAnimationDidFailCallback = () => void; declare function setEnabled(value: boolean): void; @@ -4932,8 +4943,8 @@ declare function configureNext( ): void; declare function create( duration: number, - type: LayoutAnimationType, - property: LayoutAnimationProperty + type?: LayoutAnimationType, + property?: LayoutAnimationProperty ): LayoutAnimationConfig; declare const Presets: { easeInEaseOut: LayoutAnimationConfig, @@ -4943,8 +4954,8 @@ declare const Presets: { declare const LayoutAnimation: { configureNext: configureNext, create: create, - Types: $ReadOnly<{ [K in LayoutAnimationType]: K }>, - Properties: $ReadOnly<{ [K in LayoutAnimationProperty]: K }>, + Types: LayoutAnimationTypes, + Properties: LayoutAnimationProperties, checkConfig(...args: Array): void, Presets: Presets, easeInEaseOut: (onAnimationDidEnd?: OnAnimationDidEndCallback) => void, diff --git a/scripts/build/build-types/buildTypes.js b/scripts/build/build-types/buildTypes.js index 3fb9992ff1f1..1edb3a5cc9b0 100644 --- a/scripts/build/build-types/buildTypes.js +++ b/scripts/build/build-types/buildTypes.js @@ -40,6 +40,7 @@ const ENTRY_POINTS = [ 'packages/react-native/Libraries/EventEmitter/NativeEventEmitter.js', 'packages/react-native/Libraries/EventEmitter/RCTDeviceEventEmitter.js', 'packages/react-native/Libraries/EventEmitter/RCTNativeAppEventEmitter.js', + 'packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js', 'packages/react-native/Libraries/LogBox/LogBox.js', 'packages/react-native/Libraries/Performance/Systrace.js', 'packages/react-native/Libraries/ReactNative/I18nManager.js',