MCPcopy Create free account
hub / github.com/expo/expo / loadAsync

Method loadAsync

packages/expo-image/src/ImageModule.web.ts:46–68  ·  view source on GitHub ↗
(source: ImageSource)

Source from the content-addressed store, hash-verified

44 configureCache(_: ImageCacheConfig): void {}
45
46 async loadAsync(source: ImageSource): Promise<ImageRef> {
47 if (!source.uri) {
48 // TODO: Add support for sources without the uri, e.g. blurhash and thumbhash.
49 throw new Error('The image source must have the "uri" property defined');
50 }
51 const response = await fetch(source.uri, {
52 headers: source.headers,
53 });
54
55 if (!response.ok) {
56 throw new Error(`Image request failed with the status code: ${response.status}`);
57 }
58 const blob = await response.blob();
59 const imageObjectUrl = URL.createObjectURL(blob);
60 const image = await loadImageElementAsync(imageObjectUrl);
61
62 return ImageRefWeb.init(
63 imageObjectUrl,
64 image.width,
65 image.height,
66 response.headers.get('Content-Type')
67 );
68 }
69
70 getCachePathAsync(_: string): Promise<string | null> {
71 return Promise.resolve(null);

Callers

nothing calls this directly

Calls 6

loadImageElementAsyncFunction · 0.85
createObjectURLMethod · 0.80
getMethod · 0.65
fetchFunction · 0.50
blobMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected