Skip to content

Commit 71b7dd8

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Prepare createAnimatedComponent API for flow's upcoming better react 19 ref-as-prop support (#53869)
Summary: Pull Request resolved: #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
1 parent 5b544c7 commit 71b7dd8

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

packages/react-native/Libraries/Animated/createAnimatedComponent.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,29 @@ type PassThroughProps = $ReadOnly<{
6363
passthroughAnimatedPropExplicitValues?: ViewProps | null,
6464
}>;
6565

66-
export type AnimatedProps<Props: {...}> = {
67-
[K in keyof Props]: K extends NonAnimatedProps
68-
? Props[K]
69-
: WithAnimatedValue<Props[K]>,
70-
} & PassThroughProps;
71-
72-
export type AnimatedBaseProps<Props: {...}> = {
73-
[K in keyof Props]: K extends NonAnimatedProps
74-
? Props[K]
75-
: WithAnimatedValue<Props[K]>,
76-
};
66+
type LooseOmit<O: interface {}, K: $Keys<$FlowFixMe>> = Pick<
67+
O,
68+
Exclude<$Keys<O>, K>,
69+
>;
70+
71+
export type AnimatedProps<Props: {...}> = LooseOmit<
72+
{
73+
[K in keyof Props]: K extends NonAnimatedProps
74+
? Props[K]
75+
: WithAnimatedValue<Props[K]>,
76+
},
77+
'ref',
78+
> &
79+
PassThroughProps;
80+
81+
export type AnimatedBaseProps<Props: {...}> = LooseOmit<
82+
{
83+
[K in keyof Props]: K extends NonAnimatedProps
84+
? Props[K]
85+
: WithAnimatedValue<Props[K]>,
86+
},
87+
'ref',
88+
>;
7789

7890
export type AnimatedComponentType<Props: {...}, +Instance = mixed> = component(
7991
ref?: React.RefSetter<Instance>,

packages/react-native/ReactNativeApi.d.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<69d6b949e011e87bf0e3b81098fed285>>
7+
* @generated SignedSource<<575e58047a8edf6bbc016768775a258f>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -1494,11 +1494,15 @@ declare class AnimatedNode_default {
14941494
declare type AnimatedNodeConfig = {
14951495
readonly debugID?: string
14961496
}
1497-
declare type AnimatedProps<Props extends {}> = {
1498-
[K in keyof Props]: K extends NonAnimatedProps
1499-
? Props[K]
1500-
: WithAnimatedValue<Props[K]>
1501-
} & PassThroughProps
1497+
declare type AnimatedProps<Props extends {}> = LooseOmit<
1498+
{
1499+
[K in keyof Props]: K extends NonAnimatedProps
1500+
? Props[K]
1501+
: WithAnimatedValue<Props[K]>
1502+
},
1503+
"ref"
1504+
> &
1505+
PassThroughProps
15021506
declare type AnimatedScrollViewInstance = React.ComponentRef<typeof ScrollView>
15031507
declare class AnimatedSubtraction_default extends AnimatedWithChildren_default {
15041508
constructor(
@@ -3075,6 +3079,10 @@ declare type LoopAnimationConfig = {
30753079
iterations: number
30763080
resetBeforeIteration?: boolean
30773081
}
3082+
declare type LooseOmit<O extends {}, K extends keyof any> = Pick<
3083+
O,
3084+
Exclude<keyof O, K>
3085+
>
30783086
declare type MacOSPlatform = {
30793087
OS: "macos"
30803088
select: <T>(spec: PlatformSelectSpec<T>) => T
@@ -5913,7 +5921,7 @@ export {
59135921
AlertOptions, // a0cdac0f
59145922
AlertType, // 5ab91217
59155923
AndroidKeyboardEvent, // e03becc8
5916-
Animated, // 6ad7a14c
5924+
Animated, // 6b6a0b2e
59175925
AppConfig, // ebddad4b
59185926
AppRegistry, // 6cdee1d6
59195927
AppState, // f7097b1b

0 commit comments

Comments
 (0)