Skip to content

Commit

Permalink
[react-native] Add Image.getSizeWithHeaders (DefinitelyTyped#46005)
Browse files Browse the repository at this point in the history
* Add Image.getSizeWithHeaders

* lint
  • Loading branch information
PaitoAnderson authored Jul 13, 2020
1 parent 806c044 commit edd2917
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion types/react-native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3874,7 +3874,8 @@ export interface ImageProps extends ImagePropsBase {
declare class ImageComponent extends React.Component<ImageProps> {}
declare const ImageBase: Constructor<NativeMethodsMixinType> & typeof ImageComponent;
export class Image extends ImageBase {
static getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void): any;
static getSize(uri: string, success: (width: number, height: number) => void, failure?: (error: any) => void): any;
static getSizeWithHeaders(uri: string, headers: {[index: string]: 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<{ [url: string]: 'memory' | 'disk' | 'disk/memory' }>;
Expand Down
6 changes: 6 additions & 0 deletions types/react-native/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ class StatusBarTest extends React.Component {
export class ImageTest extends React.Component {
componentDidMount(): void {
const uri = 'https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png';
const headers = { Authorization: 'Bearer test' };
const image: ImageResolvedAssetSource = Image.resolveAssetSource({ uri });
console.log(image.width, image.height, image.scale, image.uri);

Expand All @@ -811,6 +812,11 @@ export class ImageTest extends React.Component {
console.log(`Image is in ${status} cache`);
}
});

Image.getSize(uri, (width, height) => console.log(width, height));
Image.getSize(uri, (width, height) => console.log(width, height), (error) => console.error(error));
Image.getSizeWithHeaders(uri, headers, (width, height) => console.log(width, height));
Image.getSizeWithHeaders(uri, headers, (width, height) => console.log(width, height), (error) => console.error(error));
}

handleOnLoad = (e: NativeSyntheticEvent<ImageLoadEventData>) => {
Expand Down

0 comments on commit edd2917

Please sign in to comment.