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
This commit is contained in:
Sam Zhou
2025-09-21 10:49:53 -07:00
committed by Facebook GitHub Bot
parent 5b544c7cd8
commit 71b7dd8519
2 changed files with 37 additions and 17 deletions
@@ -63,17 +63,29 @@ type PassThroughProps = $ReadOnly<{
passthroughAnimatedPropExplicitValues?: ViewProps | null,
}>;
export type AnimatedProps<Props: {...}> = {
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>,
} & PassThroughProps;
type LooseOmit<O: interface {}, K: $Keys<$FlowFixMe>> = Pick<
O,
Exclude<$Keys<O>, K>,
>;
export type AnimatedBaseProps<Props: {...}> = {
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>,
};
export type AnimatedProps<Props: {...}> = LooseOmit<
{
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>,
},
'ref',
> &
PassThroughProps;
export type AnimatedBaseProps<Props: {...}> = LooseOmit<
{
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>,
},
'ref',
>;
export type AnimatedComponentType<Props: {...}, +Instance = mixed> = component(
ref?: React.RefSetter<Instance>,
+15 -7
View File
@@ -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<Props extends {}> = {
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>
} & PassThroughProps
declare type AnimatedProps<Props extends {}> = LooseOmit<
{
[K in keyof Props]: K extends NonAnimatedProps
? Props[K]
: WithAnimatedValue<Props[K]>
},
"ref"
> &
PassThroughProps
declare type AnimatedScrollViewInstance = React.ComponentRef<typeof ScrollView>
declare class AnimatedSubtraction_default extends AnimatedWithChildren_default {
constructor(
@@ -3075,6 +3079,10 @@ declare type LoopAnimationConfig = {
iterations: number
resetBeforeIteration?: boolean
}
declare type LooseOmit<O extends {}, K extends keyof any> = Pick<
O,
Exclude<keyof O, K>
>
declare type MacOSPlatform = {
OS: "macos"
select: <T>(spec: PlatformSelectSpec<T>) => T
@@ -5913,7 +5921,7 @@ export {
AlertOptions, // a0cdac0f
AlertType, // 5ab91217
AndroidKeyboardEvent, // e03becc8
Animated, // 6ad7a14c
Animated, // 6b6a0b2e
AppConfig, // ebddad4b
AppRegistry, // 6cdee1d6
AppState, // f7097b1b