diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index f0851b1af2c..28ca0348c76 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -25,6 +25,7 @@ import {convertObjectFitToResizeMode} from './ImageUtils'; import type {ImageProps as ImagePropsType} from './ImageProps'; import type {RootTag} from '../Types/RootTagTypes'; +import type {ImageAndroid} from './Image.flow'; import {getImageSourcesFromImageProps} from './ImageSourceUtils'; let _requestId = 1; @@ -331,9 +332,4 @@ const styles = StyleSheet.create({ }, }); -module.exports = ((Image: any): React.AbstractComponent< - ImagePropsType, - | React.ElementRef - | React.ElementRef, -> & - ImageComponentStatics); +module.exports = ((Image: any): ImageAndroid); diff --git a/Libraries/Image/Image.flow.js b/Libraries/Image/Image.flow.js new file mode 100644 index 00000000000..58490f04b72 --- /dev/null +++ b/Libraries/Image/Image.flow.js @@ -0,0 +1,66 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +import ImageViewNativeComponent from './ImageViewNativeComponent'; +import * as React from 'react'; + +import TextInlineImageNativeComponent from './TextInlineImageNativeComponent'; + +import type {ResolvedAssetSource} from './AssetSourceResolver'; + +import type {ImageProps as ImagePropsType} from './ImageProps'; +import type {RootTag} from '../Types/RootTagTypes'; + +type ImageComponentStaticsIOS = $ReadOnly<{| + getSize: ( + uri: string, + success: (width: number, height: number) => void, + failure?: (error: any) => void, + ) => void, + + getSizeWithHeaders( + uri: string, + headers: {[string]: string, ...}, + success: (width: number, height: number) => void, + failure?: (error: any) => void, + ): any, + + prefetch(url: string): any, + + prefetchWithMetadata( + url: string, + queryRootName: string, + rootTag?: ?RootTag, + ): any, + + queryCache( + urls: Array, + ): Promise<{[string]: 'memory' | 'disk' | 'disk/memory', ...}>, + + resolveAssetSource(source: any): ?ResolvedAssetSource, +|}>; + +type ImageComponentStaticsAndroid = { + ...ImageComponentStaticsIOS, + abortPrefetch(requestId: number): void, +}; + +export type ImageAndroid = React.AbstractComponent< + ImagePropsType, + | React.ElementRef + | React.ElementRef, +> & + ImageComponentStaticsAndroid; + +export type ImageIOS = React.AbstractComponent< + ImagePropsType, + React.ElementRef, +> & + ImageComponentStaticsIOS; diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index edf82964cb0..db7eac622ee 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -27,6 +27,8 @@ import ImageViewNativeComponent from './ImageViewNativeComponent'; import type {RootTag} from '../Types/RootTagTypes'; import {getImageSourcesFromImageProps} from './ImageSourceUtils'; +import type {ImageIOS} from './Image.flow'; + function getSize( uri: string, success: (width: number, height: number) => void, @@ -269,8 +271,4 @@ const styles = StyleSheet.create({ }, }); -module.exports = ((Image: any): React.AbstractComponent< - ImagePropsType, - React.ElementRef, -> & - ImageComponentStatics); +module.exports = ((Image: any): ImageIOS); diff --git a/Libraries/Image/ImageViewNativeComponent.js.flow b/Libraries/Image/ImageViewNativeComponent.js.flow new file mode 100644 index 00000000000..f5ca83225d5 --- /dev/null +++ b/Libraries/Image/ImageViewNativeComponent.js.flow @@ -0,0 +1,45 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +import type {ResolvedAssetSource} from './AssetSourceResolver'; +import type {ImageProps} from './ImageProps'; +import type {ViewProps} from '../Components/View/ViewPropTypes'; +import {ConditionallyIgnoredEventHandlers} from '../NativeComponent/ViewConfigIgnore'; +import type { + HostComponent, + PartialViewConfig, +} from '../Renderer/shims/ReactNativeTypes'; +import type { + ColorValue, + DangerouslyImpreciseStyle, + ImageStyleProp, +} from '../StyleSheet/StyleSheet'; +import Platform from '../Utilities/Platform'; + +type Props = $ReadOnly<{ + ...ImageProps, + ...ViewProps, + + style?: ImageStyleProp | DangerouslyImpreciseStyle, + + // iOS native props + tintColor?: ColorValue, + + // Android native props + shouldNotifyLoadEvents?: boolean, + src?: + | ?ResolvedAssetSource + | ?$ReadOnlyArray>, + headers?: ?{[string]: string}, + defaultSrc?: ?string, + loadingIndicatorSrc?: ?string, +}>; + +declare export default HostComponent; diff --git a/Libraries/Image/TextInlineImageNativeComponent.js.flow b/Libraries/Image/TextInlineImageNativeComponent.js.flow new file mode 100644 index 00000000000..6726b15d47a --- /dev/null +++ b/Libraries/Image/TextInlineImageNativeComponent.js.flow @@ -0,0 +1,27 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict-local + */ + +'use strict'; + +import type {HostComponent} from '../Renderer/shims/ReactNativeTypes'; +import type {ViewProps} from '../Components/View/ViewPropTypes'; +import type {ImageResizeMode} from './ImageResizeMode'; +import * as NativeComponentRegistry from '../NativeComponent/NativeComponentRegistry'; +import type {ColorValue} from '../StyleSheet/StyleSheet'; + +type NativeProps = $ReadOnly<{ + ...ViewProps, + resizeMode?: ?ImageResizeMode, + src?: ?$ReadOnlyArray>, + tintColor?: ?ColorValue, + headers?: ?{[string]: string}, +}>; + +declare export default HostComponent;