RN - Change Image props/static methods

This commit is contained in:
Alexaner T
2018-06-25 18:21:13 +03:00
parent c706dd900f
commit 553a72da2f
2 changed files with 35 additions and 5 deletions

View File

@@ -3259,7 +3259,7 @@ export interface SwitchIOSProps extends ViewProps {
*/
export class SwitchIOS extends React.Component<SwitchIOSProps> {}
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<ImageProps> {}
declare const ImageBase: Constructor<NativeMethodsMixin> & 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<Map<string, "memory" | "disk">>;
/**
* @see https://facebook.github.io/react-native/docs/image.html#resolveassetsource
*/
static resolveAssetSource(source: ImageSourcePropType): ImageResolvedAssetSource;
}
export interface ImageBackgroundProps extends ImagePropsBase {

View File

@@ -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<ImageLoadEventData>) {
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 (
<View>
<Image
source={{ uri: 'https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png' }}
onLoad={this.onLoad}
/>
<Image
source={{ uri: 'https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png' }}
resizeMode={resizeMode}
/>
</View>
);
}