From 71b7dd8519b4a6dbd1a97cd15ca89b5271b9074e Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sun, 21 Sep 2025 10:49:53 -0700 Subject: [PATCH] Prepare createAnimatedComponent API for flow's upcoming better react 19 ref-as-prop support (#53869) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53869 This is a prep step to enable better Flow support for react 19 ref-as-prop. While it causes changes in the ReactNativeApi.d.ts snapshot, it should preserve the existing type behavior, since in the TS version, the ref prop will be excluded anyways: https://github.com/facebook/react-native/blob/a4d43290c82e8ad93f03b304a78cdf0eaf41fba1/packages/react-native/ReactNativeApi.d.ts#L1434 Changelog: [Internal] Reviewed By: jbrown215 Differential Revision: D82916014 fbshipit-source-id: 2e62aab493dcf6f8f5e382c0739060c88e6f7ed5 --- .../Animated/createAnimatedComponent.js | 32 +++++++++++++------ packages/react-native/ReactNativeApi.d.ts | 22 +++++++++---- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/packages/react-native/Libraries/Animated/createAnimatedComponent.js b/packages/react-native/Libraries/Animated/createAnimatedComponent.js index 345c1ac29ab..f9970a1cc31 100644 --- a/packages/react-native/Libraries/Animated/createAnimatedComponent.js +++ b/packages/react-native/Libraries/Animated/createAnimatedComponent.js @@ -63,17 +63,29 @@ type PassThroughProps = $ReadOnly<{ passthroughAnimatedPropExplicitValues?: ViewProps | null, }>; -export type AnimatedProps = { - [K in keyof Props]: K extends NonAnimatedProps - ? Props[K] - : WithAnimatedValue, -} & PassThroughProps; +type LooseOmit> = Pick< + O, + Exclude<$Keys, K>, +>; -export type AnimatedBaseProps = { - [K in keyof Props]: K extends NonAnimatedProps - ? Props[K] - : WithAnimatedValue, -}; +export type AnimatedProps = LooseOmit< + { + [K in keyof Props]: K extends NonAnimatedProps + ? Props[K] + : WithAnimatedValue, + }, + 'ref', +> & + PassThroughProps; + +export type AnimatedBaseProps = LooseOmit< + { + [K in keyof Props]: K extends NonAnimatedProps + ? Props[K] + : WithAnimatedValue, + }, + 'ref', +>; export type AnimatedComponentType = component( ref?: React.RefSetter, diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index e1bb4297e72..7771f1d4193 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<69d6b949e011e87bf0e3b81098fed285>> + * @generated SignedSource<<575e58047a8edf6bbc016768775a258f>> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -1494,11 +1494,15 @@ declare class AnimatedNode_default { declare type AnimatedNodeConfig = { readonly debugID?: string } -declare type AnimatedProps = { - [K in keyof Props]: K extends NonAnimatedProps - ? Props[K] - : WithAnimatedValue -} & PassThroughProps +declare type AnimatedProps = LooseOmit< + { + [K in keyof Props]: K extends NonAnimatedProps + ? Props[K] + : WithAnimatedValue + }, + "ref" +> & + PassThroughProps declare type AnimatedScrollViewInstance = React.ComponentRef declare class AnimatedSubtraction_default extends AnimatedWithChildren_default { constructor( @@ -3075,6 +3079,10 @@ declare type LoopAnimationConfig = { iterations: number resetBeforeIteration?: boolean } +declare type LooseOmit = Pick< + O, + Exclude +> declare type MacOSPlatform = { OS: "macos" select: (spec: PlatformSelectSpec) => T @@ -5913,7 +5921,7 @@ export { AlertOptions, // a0cdac0f AlertType, // 5ab91217 AndroidKeyboardEvent, // e03becc8 - Animated, // 6ad7a14c + Animated, // 6b6a0b2e AppConfig, // ebddad4b AppRegistry, // 6cdee1d6 AppState, // f7097b1b