Simplify some RN types (#53868)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53868

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, this diff simply inlines what these `React.ElementRef` evaluates into.

Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D82915646

fbshipit-source-id: 64179eac7dde91381361fb9f1053d58100d864c3
This commit is contained in:
Sam Zhou authored and Facebook GitHub Bot committed 2025-09-21 10:49:53 -07:00
1 parent a4d43290c8
commit 5b544c7cd8
4 files changed
+18 -82

No files matched your search

+3 -6
View File
@@ -8,11 +8,8 @@
* @format
*/
import type {
AbstractImageAndroid,
AbstractImageIOS,
ImageType as ImageComponent,
} from './ImageTypes.flow';
import type {HostInstance} from '../..';
import type {AbstractImageAndroid, AbstractImageIOS} from './ImageTypes.flow';
import useMergeRefs from '../Utilities/useMergeRefs';
import * as React from 'react';
@@ -33,7 +30,7 @@ export function unstable_getImageComponentDecorator(): ?ImageComponentDecorator
return injectedImageComponentDecorator;
}
type ImageInstance = React.ElementRef<ImageComponent>;
type ImageInstance = HostInstance;
type ImageAttachedCallback = (
imageInstance: ImageInstance,
@@ -8,12 +8,11 @@
* @format
*/
import type {HostInstance} from '../..';
import type {RootTag} from '../Types/RootTagTypes';
import type {ResolvedAssetSource} from './AssetSourceResolver';
import type {ImageProps as ImagePropsType} from './ImageProps';
import type {ImageSource} from './ImageSource';
import typeof ImageViewNativeComponent from './ImageViewNativeComponent';
import typeof TextInlineImageNativeComponent from './TextInlineImageNativeComponent';
import * as React from 'react';
@@ -67,17 +66,14 @@ type ImageComponentStaticsAndroid = $ReadOnly<{
}>;
export type AbstractImageAndroid = component(
ref?: React.RefSetter<
| React.ElementRef<TextInlineImageNativeComponent>
| React.ElementRef<ImageViewNativeComponent>,
>,
ref?: React.RefSetter<HostInstance>,
...props: ImagePropsType
);
export type ImageAndroid = AbstractImageAndroid & ImageComponentStaticsAndroid;
export type AbstractImageIOS = component(
ref?: React.RefSetter<React.ElementRef<ImageViewNativeComponent>>,
ref?: React.RefSetter<HostInstance>,
...props: ImagePropsType
);
+8 -62
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<<377660a4dc9f8c721ebcd64f759637ac>>
* @generated SignedSource<<69d6b949e011e87bf0e3b81098fed285>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
@@ -77,7 +77,6 @@ declare const $$AnimatedView: AnimatedComponentType<
React.ComponentRef<typeof View>
>
declare const $$flattenStyle: typeof flattenStyle_default
declare const $$ImageViewNativeComponent: typeof ImageViewNativeComponent_default
declare const $$index: {
keyExtractor: typeof keyExtractor
get FillRateHelper(): FillRateHelperT
@@ -92,7 +91,6 @@ declare const $$ProgressBarAndroidNativeComponent: HostComponent<AndroidProgress
declare const $$ScrollViewContext: typeof ScrollViewContext_default
declare const $$ScrollViewNativeComponent: typeof ScrollViewNativeComponent_default
declare const $$SwitchNativeComponent: ComponentType
declare const $$TextInlineImageNativeComponent: typeof TextInlineImage_default
declare const $$ViewNativeComponent: typeof ViewNativeComponent_default
declare const absoluteFill: AbsoluteFillStyle
declare const absoluteFillObject: AbsoluteFillStyle
@@ -254,7 +252,6 @@ declare const I18nManager: {
swapLeftAndRightInRTL: (flipStyles: boolean) => void
}
declare const Image: ImageType
declare const ImageViewNativeComponent_default: HostComponent<ImageHostComponentProps>
declare const InputAccessoryView: typeof InputAccessoryView_default
declare const InputAccessoryView_default: React.ComponentType<InputAccessoryViewProps>
declare const InteractionManager: typeof InteractionManagerStub_default
@@ -465,7 +462,6 @@ declare const TextImpl_default: (
ref?: React.Ref<TextForwardRef>
},
) => React.ReactNode
declare const TextInlineImage_default: HostComponent<RCTTextInlineImageNativeProps>
declare const TextInput: TextInputType
declare const timing: typeof $$AnimatedImplementation.timing
declare const timingImpl: (
@@ -1013,7 +1009,6 @@ declare type $$AnimatedSectionList = typeof $$AnimatedSectionList
declare type $$AnimatedText = typeof $$AnimatedText
declare type $$AnimatedView = typeof $$AnimatedView
declare type $$flattenStyle = typeof $$flattenStyle
declare type $$ImageViewNativeComponent = typeof $$ImageViewNativeComponent
declare type $$index = typeof $$index
declare type $$NativeDeviceInfo = typeof $$NativeDeviceInfo
declare type $$NativeDialogManagerAndroid = typeof $$NativeDialogManagerAndroid
@@ -1022,8 +1017,6 @@ declare type $$ProgressBarAndroidNativeComponent =
declare type $$ScrollViewContext = typeof $$ScrollViewContext
declare type $$ScrollViewNativeComponent = typeof $$ScrollViewNativeComponent
declare type $$SwitchNativeComponent = typeof $$SwitchNativeComponent
declare type $$TextInlineImageNativeComponent =
typeof $$TextInlineImageNativeComponent
declare type $$ViewNativeComponent = typeof $$ViewNativeComponent
declare type absoluteFill = typeof absoluteFill
declare type absoluteFillObject = typeof absoluteFillObject
@@ -1036,15 +1029,12 @@ declare type AbsoluteFillStyle = {
}
declare type AbstractImageAndroid = (
props: ImageProps & {
ref?: React.Ref<
| React.ComponentRef<ImageViewNativeComponent>
| React.ComponentRef<TextInlineImageNativeComponent>
>
ref?: React.Ref<HostInstance>
},
) => React.ReactNode
declare type AbstractImageIOS = (
props: ImageProps & {
ref?: React.Ref<React.ComponentRef<ImageViewNativeComponent>>
ref?: React.Ref<HostInstance>
},
) => React.ReactNode
declare type AccessibilityActionEvent = NativeSyntheticEvent<{
@@ -1899,7 +1889,7 @@ declare type ContentAvailable = 1 | null | void
declare type Context = {
readonly cellKey: string | undefined
readonly horizontal: boolean | undefined
readonly getOutermostParentListRef: () => React.ComponentRef<VirtualizedListT_2>
readonly getOutermostParentListRef: () => VirtualizedList_default
readonly getScrollMetrics: () => {
contentLength: number
dOffset: number
@@ -1912,10 +1902,10 @@ declare type Context = {
}
readonly registerAsNestedChild: ($$PARAM_0$$: {
cellKey: string
ref: React.ComponentRef<VirtualizedListT_2>
ref: VirtualizedList_default
}) => void
readonly unregisterAsNestedChild: ($$PARAM_0$$: {
ref: React.ComponentRef<VirtualizedListT_2>
ref: VirtualizedList_default
}) => void
}
declare function counterEvent(eventName: EventName, value: number): void
@@ -1940,7 +1930,6 @@ declare function createPublicTextInstance(
): ReadOnlyText_default
declare type createPublicTextInstanceT = typeof createPublicTextInstance
declare type CursorValue = "auto" | "pointer"
declare type DangerouslyImpreciseStyle = ____DangerouslyImpreciseStyle_Internal
declare type DataDetectorTypesType =
| "address"
| "all"
@@ -2594,30 +2583,6 @@ declare type ImageErrorEvent = NativeSyntheticEvent<
declare type ImageErrorEventData = {
error: string
}
declare type ImageHostComponentProps = Readonly<
ImageProps &
Omit<ViewProps, "style"> & {
defaultSource?: (ImageSource | undefined) | (string | undefined)
headers?: {
[$$Key$$: string]: string
}
loadingIndicatorSrc?: string
shouldNotifyLoadEvents?: boolean
src?:
| (
| ReadonlyArray<
| undefined
| {
readonly uri?: string
}
>
| undefined
)
| (ResolvedAssetSource | undefined)
style?: DangerouslyImpreciseStyle | ImageStyleProp
tintColor?: ColorValue
}
>
declare type ImageIOS = AbstractImageIOS & ImageComponentStaticsIOS
declare type ImageLoadEvent = NativeSyntheticEvent<Readonly<ImageLoadEventData>>
declare type ImageLoadEventData = {
@@ -2732,7 +2697,6 @@ declare interface ImageURISource {
readonly uri?: string
readonly width?: number
}
declare type ImageViewNativeComponent = typeof $$ImageViewNativeComponent
declare type IndeterminateProgressBarAndroidStyleAttrProp = {
indeterminate: true
styleAttr:
@@ -3971,21 +3935,6 @@ declare type RCTNetworkingEventDefinitions = {
]
readonly didSendNetworkData: [[number, number, number]]
}
declare type RCTTextInlineImageNativeProps = Readonly<
ViewProps & {
headers?: {
[$$Key$$: string]: string
}
resizeMode?: ImageResizeMode
src?: ReadonlyArray<
| undefined
| {
readonly uri?: string
}
>
tintColor?: ColorValue
}
>
declare class ReactNativeDocument_default extends ReadOnlyNode_default {
get childElementCount(): number
get children(): HTMLCollection_default<ReadOnlyElement_default>
@@ -5161,8 +5110,6 @@ declare type TextContentType =
declare type TextForwardRef = React.ComponentRef<
typeof NativeText | typeof NativeVirtualText
>
declare type TextInlineImageNativeComponent =
typeof $$TextInlineImageNativeComponent
declare type TextInput = typeof TextInput
declare type TextInputAndroidProps = {
readonly cursorColor?: ColorValue
@@ -5856,7 +5803,6 @@ declare type VirtualizedListProps = ScrollViewProps &
RequiredVirtualizedListProps &
OptionalVirtualizedListProps
declare type VirtualizedListT = typeof VirtualizedList_default
declare type VirtualizedListT_2 = typeof VirtualizedList_default
declare type VirtualizedListType = typeof $$index.VirtualizedList
declare type VirtualizedSectionList = typeof VirtualizedSectionList
declare type VirtualizedSectionListProps<
@@ -6026,8 +5972,8 @@ export {
IOSKeyboardEvent, // e67bfe3a
IgnorePattern, // ec6f6ece
Image, // 04474205
ImageBackground, // e74abb26
ImageBackgroundProps, // cadc2fba
ImageBackground, // 489b1c17
ImageBackgroundProps, // 1b209e36
ImageErrorEvent, // b7b2ae63
ImageLoadEvent, // 5baae813
ImageProgressEventIOS, // adb35052
@@ -8,7 +8,7 @@
* @format
*/
import typeof VirtualizedListT from './VirtualizedList';
import type VirtualizedList from './VirtualizedList';
import * as React from 'react';
import {createContext, useContext, useMemo} from 'react';
@@ -26,12 +26,9 @@ type Context = $ReadOnly<{
zoomScale: number,
},
horizontal: ?boolean,
getOutermostParentListRef: () => React.ElementRef<VirtualizedListT>,
registerAsNestedChild: ({
cellKey: string,
ref: React.ElementRef<VirtualizedListT>,
}) => void,
unregisterAsNestedChild: ({ref: React.ElementRef<VirtualizedListT>}) => void,
getOutermostParentListRef: () => VirtualizedList,
registerAsNestedChild: ({cellKey: string, ref: VirtualizedList}) => void,
unregisterAsNestedChild: ({ref: VirtualizedList}) => void,
}>;
export const VirtualizedListContext: React.Context<?Context> =