From 553a72da2fee92ce0415d52bc4d9aede04586d99 Mon Sep 17 00:00:00 2001 From: Alexaner T Date: Mon, 25 Jun 2018 18:21:13 +0300 Subject: [PATCH] RN - Change Image props/static methods --- types/react-native/index.d.ts | 24 +++++++++++++++++++----- types/react-native/test/index.tsx | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 20007e80c8..5ba2ea01c8 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -3259,7 +3259,7 @@ export interface SwitchIOSProps extends ViewProps { */ export class SwitchIOS extends React.Component {} -export type ImageResizeMode = "contain" | "cover" | "stretch" | "center" | "repeat"; +export type ImageResizeMode = "cover" | "contain" | "stretch" | "repeat" | "center"; /** * @see ImageResizeMode.js @@ -3456,11 +3456,11 @@ export type ImageSourcePropType = ImageURISource | ImageURISource[] | ImageRequi /** * @see ImagePropsBase.onLoad */ -interface ImageLoadEventDataAndroid { +export interface ImageLoadEventDataAndroid { uri?: string; } -interface ImageLoadEventData extends ImageLoadEventDataAndroid { +export interface ImageLoadEventData extends ImageLoadEventDataAndroid { source: { height: number; width: number; @@ -3468,6 +3468,16 @@ interface ImageLoadEventData extends ImageLoadEventDataAndroid { } } +/** + * @see https://facebook.github.io/react-native/docs/image.html#resolveassetsource + */ +export interface ImageResolvedAssetSource { + height: number; + width: number; + scale: number; + uri: string; +} + /** * @see https://facebook.github.io/react-native/docs/image.html */ @@ -3536,7 +3546,7 @@ export interface ImagePropsBase extends ImagePropsIOS, ImagePropsAndroid, Access * if bigger than the area of the view. * The image will not be scaled up. */ - resizeMode?: "cover" | "contain" | "stretch" | "repeat" | "center"; + resizeMode?: ImageResizeMode; /** * The mechanism that should be used to resize the image when the image's dimensions @@ -3602,11 +3612,15 @@ export interface ImageProps extends ImagePropsBase { declare class ImageComponent extends React.Component {} declare const ImageBase: Constructor & typeof ImageComponent; export class Image extends ImageBase { - resizeMode: ImageResizeMode; static getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void): any; static prefetch(url: string): any; static abortPrefetch?(requestId: number): void; static queryCache?(urls: string[]): Promise>; + + /** + * @see https://facebook.github.io/react-native/docs/image.html#resolveassetsource + */ + static resolveAssetSource(source: ImageSourcePropType): ImageResolvedAssetSource; } export interface ImageBackgroundProps extends ImagePropsBase { diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 344ff02fae..022ab8a37b 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -24,7 +24,9 @@ import { Dimensions, Image, ImageStyle, + ImageResizeMode, ImageLoadEventData, + ImageResolvedAssetSource, InteractionManager, ListView, ListViewDataSource, @@ -557,6 +559,13 @@ class StatusBarTest extends React.Component { } export class ImageTest extends React.Component { + componentDidMount(): void { + const image: ImageResolvedAssetSource = Image.resolveAssetSource({ + uri: 'https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png' + }); + console.log(image.width, image.height, image.scale, image.uri); + } + onLoad(e: NativeSyntheticEvent) { testNativeSyntheticEvent(e); console.log('height:', e.nativeEvent.source.height); @@ -565,12 +574,19 @@ export class ImageTest extends React.Component { } render() { + const resizeMode: ImageResizeMode = 'contain'; + return ( + + ); }