Skip to content

Commit 5b544c7

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Simplify some RN types (#53868)
Summary: Pull Request resolved: #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
1 parent a4d4329 commit 5b544c7

4 files changed

Lines changed: 18 additions & 82 deletions

File tree

packages/react-native/Libraries/Image/ImageInjection.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
* @format
99
*/
1010

11-
import type {
12-
AbstractImageAndroid,
13-
AbstractImageIOS,
14-
ImageType as ImageComponent,
15-
} from './ImageTypes.flow';
11+
import type {HostInstance} from '../..';
12+
import type {AbstractImageAndroid, AbstractImageIOS} from './ImageTypes.flow';
1613

1714
import useMergeRefs from '../Utilities/useMergeRefs';
1815
import * as React from 'react';
@@ -33,7 +30,7 @@ export function unstable_getImageComponentDecorator(): ?ImageComponentDecorator
3330
return injectedImageComponentDecorator;
3431
}
3532

36-
type ImageInstance = React.ElementRef<ImageComponent>;
33+
type ImageInstance = HostInstance;
3734

3835
type ImageAttachedCallback = (
3936
imageInstance: ImageInstance,

packages/react-native/Libraries/Image/ImageTypes.flow.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
* @format
99
*/
1010

11+
import type {HostInstance} from '../..';
1112
import type {RootTag} from '../Types/RootTagTypes';
1213
import type {ResolvedAssetSource} from './AssetSourceResolver';
1314
import type {ImageProps as ImagePropsType} from './ImageProps';
1415
import type {ImageSource} from './ImageSource';
15-
import typeof ImageViewNativeComponent from './ImageViewNativeComponent';
16-
import typeof TextInlineImageNativeComponent from './TextInlineImageNativeComponent';
1716

1817
import * as React from 'react';
1918

@@ -67,17 +66,14 @@ type ImageComponentStaticsAndroid = $ReadOnly<{
6766
}>;
6867

6968
export type AbstractImageAndroid = component(
70-
ref?: React.RefSetter<
71-
| React.ElementRef<TextInlineImageNativeComponent>
72-
| React.ElementRef<ImageViewNativeComponent>,
73-
>,
69+
ref?: React.RefSetter<HostInstance>,
7470
...props: ImagePropsType
7571
);
7672

7773
export type ImageAndroid = AbstractImageAndroid & ImageComponentStaticsAndroid;
7874

7975
export type AbstractImageIOS = component(
80-
ref?: React.RefSetter<React.ElementRef<ImageViewNativeComponent>>,
76+
ref?: React.RefSetter<HostInstance>,
8177
...props: ImagePropsType
8278
);
8379

packages/react-native/ReactNativeApi.d.ts

Lines changed: 8 additions & 62 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<<377660a4dc9f8c721ebcd64f759637ac>>
7+
* @generated SignedSource<<69d6b949e011e87bf0e3b81098fed285>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -77,7 +77,6 @@ declare const $$AnimatedView: AnimatedComponentType<
7777
React.ComponentRef<typeof View>
7878
>
7979
declare const $$flattenStyle: typeof flattenStyle_default
80-
declare const $$ImageViewNativeComponent: typeof ImageViewNativeComponent_default
8180
declare const $$index: {
8281
keyExtractor: typeof keyExtractor
8382
get FillRateHelper(): FillRateHelperT
@@ -92,7 +91,6 @@ declare const $$ProgressBarAndroidNativeComponent: HostComponent<AndroidProgress
9291
declare const $$ScrollViewContext: typeof ScrollViewContext_default
9392
declare const $$ScrollViewNativeComponent: typeof ScrollViewNativeComponent_default
9493
declare const $$SwitchNativeComponent: ComponentType
95-
declare const $$TextInlineImageNativeComponent: typeof TextInlineImage_default
9694
declare const $$ViewNativeComponent: typeof ViewNativeComponent_default
9795
declare const absoluteFill: AbsoluteFillStyle
9896
declare const absoluteFillObject: AbsoluteFillStyle
@@ -254,7 +252,6 @@ declare const I18nManager: {
254252
swapLeftAndRightInRTL: (flipStyles: boolean) => void
255253
}
256254
declare const Image: ImageType
257-
declare const ImageViewNativeComponent_default: HostComponent<ImageHostComponentProps>
258255
declare const InputAccessoryView: typeof InputAccessoryView_default
259256
declare const InputAccessoryView_default: React.ComponentType<InputAccessoryViewProps>
260257
declare const InteractionManager: typeof InteractionManagerStub_default
@@ -465,7 +462,6 @@ declare const TextImpl_default: (
465462
ref?: React.Ref<TextForwardRef>
466463
},
467464
) => React.ReactNode
468-
declare const TextInlineImage_default: HostComponent<RCTTextInlineImageNativeProps>
469465
declare const TextInput: TextInputType
470466
declare const timing: typeof $$AnimatedImplementation.timing
471467
declare const timingImpl: (
@@ -1013,7 +1009,6 @@ declare type $$AnimatedSectionList = typeof $$AnimatedSectionList
10131009
declare type $$AnimatedText = typeof $$AnimatedText
10141010
declare type $$AnimatedView = typeof $$AnimatedView
10151011
declare type $$flattenStyle = typeof $$flattenStyle
1016-
declare type $$ImageViewNativeComponent = typeof $$ImageViewNativeComponent
10171012
declare type $$index = typeof $$index
10181013
declare type $$NativeDeviceInfo = typeof $$NativeDeviceInfo
10191014
declare type $$NativeDialogManagerAndroid = typeof $$NativeDialogManagerAndroid
@@ -1022,8 +1017,6 @@ declare type $$ProgressBarAndroidNativeComponent =
10221017
declare type $$ScrollViewContext = typeof $$ScrollViewContext
10231018
declare type $$ScrollViewNativeComponent = typeof $$ScrollViewNativeComponent
10241019
declare type $$SwitchNativeComponent = typeof $$SwitchNativeComponent
1025-
declare type $$TextInlineImageNativeComponent =
1026-
typeof $$TextInlineImageNativeComponent
10271020
declare type $$ViewNativeComponent = typeof $$ViewNativeComponent
10281021
declare type absoluteFill = typeof absoluteFill
10291022
declare type absoluteFillObject = typeof absoluteFillObject
@@ -1036,15 +1029,12 @@ declare type AbsoluteFillStyle = {
10361029
}
10371030
declare type AbstractImageAndroid = (
10381031
props: ImageProps & {
1039-
ref?: React.Ref<
1040-
| React.ComponentRef<ImageViewNativeComponent>
1041-
| React.ComponentRef<TextInlineImageNativeComponent>
1042-
>
1032+
ref?: React.Ref<HostInstance>
10431033
},
10441034
) => React.ReactNode
10451035
declare type AbstractImageIOS = (
10461036
props: ImageProps & {
1047-
ref?: React.Ref<React.ComponentRef<ImageViewNativeComponent>>
1037+
ref?: React.Ref<HostInstance>
10481038
},
10491039
) => React.ReactNode
10501040
declare type AccessibilityActionEvent = NativeSyntheticEvent<{
@@ -1899,7 +1889,7 @@ declare type ContentAvailable = 1 | null | void
18991889
declare type Context = {
19001890
readonly cellKey: string | undefined
19011891
readonly horizontal: boolean | undefined
1902-
readonly getOutermostParentListRef: () => React.ComponentRef<VirtualizedListT_2>
1892+
readonly getOutermostParentListRef: () => VirtualizedList_default
19031893
readonly getScrollMetrics: () => {
19041894
contentLength: number
19051895
dOffset: number
@@ -1912,10 +1902,10 @@ declare type Context = {
19121902
}
19131903
readonly registerAsNestedChild: ($$PARAM_0$$: {
19141904
cellKey: string
1915-
ref: React.ComponentRef<VirtualizedListT_2>
1905+
ref: VirtualizedList_default
19161906
}) => void
19171907
readonly unregisterAsNestedChild: ($$PARAM_0$$: {
1918-
ref: React.ComponentRef<VirtualizedListT_2>
1908+
ref: VirtualizedList_default
19191909
}) => void
19201910
}
19211911
declare function counterEvent(eventName: EventName, value: number): void
@@ -1940,7 +1930,6 @@ declare function createPublicTextInstance(
19401930
): ReadOnlyText_default
19411931
declare type createPublicTextInstanceT = typeof createPublicTextInstance
19421932
declare type CursorValue = "auto" | "pointer"
1943-
declare type DangerouslyImpreciseStyle = ____DangerouslyImpreciseStyle_Internal
19441933
declare type DataDetectorTypesType =
19451934
| "address"
19461935
| "all"
@@ -2594,30 +2583,6 @@ declare type ImageErrorEvent = NativeSyntheticEvent<
25942583
declare type ImageErrorEventData = {
25952584
error: string
25962585
}
2597-
declare type ImageHostComponentProps = Readonly<
2598-
ImageProps &
2599-
Omit<ViewProps, "style"> & {
2600-
defaultSource?: (ImageSource | undefined) | (string | undefined)
2601-
headers?: {
2602-
[$$Key$$: string]: string
2603-
}
2604-
loadingIndicatorSrc?: string
2605-
shouldNotifyLoadEvents?: boolean
2606-
src?:
2607-
| (
2608-
| ReadonlyArray<
2609-
| undefined
2610-
| {
2611-
readonly uri?: string
2612-
}
2613-
>
2614-
| undefined
2615-
)
2616-
| (ResolvedAssetSource | undefined)
2617-
style?: DangerouslyImpreciseStyle | ImageStyleProp
2618-
tintColor?: ColorValue
2619-
}
2620-
>
26212586
declare type ImageIOS = AbstractImageIOS & ImageComponentStaticsIOS
26222587
declare type ImageLoadEvent = NativeSyntheticEvent<Readonly<ImageLoadEventData>>
26232588
declare type ImageLoadEventData = {
@@ -2732,7 +2697,6 @@ declare interface ImageURISource {
27322697
readonly uri?: string
27332698
readonly width?: number
27342699
}
2735-
declare type ImageViewNativeComponent = typeof $$ImageViewNativeComponent
27362700
declare type IndeterminateProgressBarAndroidStyleAttrProp = {
27372701
indeterminate: true
27382702
styleAttr:
@@ -3971,21 +3935,6 @@ declare type RCTNetworkingEventDefinitions = {
39713935
]
39723936
readonly didSendNetworkData: [[number, number, number]]
39733937
}
3974-
declare type RCTTextInlineImageNativeProps = Readonly<
3975-
ViewProps & {
3976-
headers?: {
3977-
[$$Key$$: string]: string
3978-
}
3979-
resizeMode?: ImageResizeMode
3980-
src?: ReadonlyArray<
3981-
| undefined
3982-
| {
3983-
readonly uri?: string
3984-
}
3985-
>
3986-
tintColor?: ColorValue
3987-
}
3988-
>
39893938
declare class ReactNativeDocument_default extends ReadOnlyNode_default {
39903939
get childElementCount(): number
39913940
get children(): HTMLCollection_default<ReadOnlyElement_default>
@@ -5161,8 +5110,6 @@ declare type TextContentType =
51615110
declare type TextForwardRef = React.ComponentRef<
51625111
typeof NativeText | typeof NativeVirtualText
51635112
>
5164-
declare type TextInlineImageNativeComponent =
5165-
typeof $$TextInlineImageNativeComponent
51665113
declare type TextInput = typeof TextInput
51675114
declare type TextInputAndroidProps = {
51685115
readonly cursorColor?: ColorValue
@@ -5856,7 +5803,6 @@ declare type VirtualizedListProps = ScrollViewProps &
58565803
RequiredVirtualizedListProps &
58575804
OptionalVirtualizedListProps
58585805
declare type VirtualizedListT = typeof VirtualizedList_default
5859-
declare type VirtualizedListT_2 = typeof VirtualizedList_default
58605806
declare type VirtualizedListType = typeof $$index.VirtualizedList
58615807
declare type VirtualizedSectionList = typeof VirtualizedSectionList
58625808
declare type VirtualizedSectionListProps<
@@ -6026,8 +5972,8 @@ export {
60265972
IOSKeyboardEvent, // e67bfe3a
60275973
IgnorePattern, // ec6f6ece
60285974
Image, // 04474205
6029-
ImageBackground, // e74abb26
6030-
ImageBackgroundProps, // cadc2fba
5975+
ImageBackground, // 489b1c17
5976+
ImageBackgroundProps, // 1b209e36
60315977
ImageErrorEvent, // b7b2ae63
60325978
ImageLoadEvent, // 5baae813
60335979
ImageProgressEventIOS, // adb35052

packages/virtualized-lists/Lists/VirtualizedListContext.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
import typeof VirtualizedListT from './VirtualizedList';
11+
import type VirtualizedList from './VirtualizedList';
1212

1313
import * as React from 'react';
1414
import {createContext, useContext, useMemo} from 'react';
@@ -26,12 +26,9 @@ type Context = $ReadOnly<{
2626
zoomScale: number,
2727
},
2828
horizontal: ?boolean,
29-
getOutermostParentListRef: () => React.ElementRef<VirtualizedListT>,
30-
registerAsNestedChild: ({
31-
cellKey: string,
32-
ref: React.ElementRef<VirtualizedListT>,
33-
}) => void,
34-
unregisterAsNestedChild: ({ref: React.ElementRef<VirtualizedListT>}) => void,
29+
getOutermostParentListRef: () => VirtualizedList,
30+
registerAsNestedChild: ({cellKey: string, ref: VirtualizedList}) => void,
31+
unregisterAsNestedChild: ({ref: VirtualizedList}) => void,
3532
}>;
3633

3734
export const VirtualizedListContext: React.Context<?Context> =

0 commit comments

Comments
 (0)