react-native: Fix the return type of queryCache (#35681)

* Fix the return type of queryCache

Ref: https://github.com/facebook/react-native/pull/23602

* fix

* lint

* Add queryCache test to Image
This commit is contained in:
George Cheng
2019-05-24 10:50:42 +02:00
committed by Eloy Durán
parent 674a7033d6
commit cdc4f7e325
2 changed files with 12 additions and 5 deletions
+2 -2
View File
@@ -3992,7 +3992,7 @@ export class Image extends ImageBase {
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">>;
static queryCache?(urls: string[]): Promise<{[url: string]: "memory" | "disk" | "disk/memory"}>;
/**
* @see https://facebook.github.io/react-native/docs/image.html#resolveassetsource
@@ -4013,7 +4013,7 @@ export class ImageBackground extends ImageBackgroundBase {
getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void): any;
prefetch(url: string): any;
abortPrefetch?(requestId: number): void;
queryCache?(urls: string[]): Promise<Map<string, "memory" | "disk">>;
queryCache?(urls: string[]): Promise<{[url: string]: "memory" | "disk" | "disk/memory"}>;
}
export interface ViewToken {
+10 -3
View File
@@ -701,10 +701,17 @@ class WebViewTest 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",
});
const uri = "https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png";
const image: ImageResolvedAssetSource = Image.resolveAssetSource({ uri });
console.log(image.width, image.height, image.scale, image.uri);
Image.queryCache([uri]).then(({ [uri]: status }) => {
if (status === undefined) {
console.log("Image is not in cache");
} else {
console.log(`Image is in ${status} cache`);
}
})
}
handleOnLoad = (e: NativeSyntheticEvent<ImageLoadEventData>) => {