mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
RN - Change Image props/static methods
This commit is contained in:
24
types/react-native/index.d.ts
vendored
24
types/react-native/index.d.ts
vendored
@@ -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 {
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user