Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/react-native-web/src/exports/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ interface ImageStatics {
failure: () => void
) => void;
prefetch: (uri: string) => Promise<void>;
resolveAssetSource: (source: $PropertyType<ImageProps, 'source'>) => {
height: ?number,
width: ?number,
scale: number,
uri: string
};
queryCache: (
uris: Array<string>
) => Promise<{| [uri: string]: 'disk/memory' |}>;
Expand Down Expand Up @@ -375,6 +381,30 @@ ImageWithStatics.queryCache = function (uris) {
return ImageLoader.queryCache(uris);
};

ImageWithStatics.resolveAssetSource = function (source) {
if (typeof source !== 'number') {
throw new Error(
'May only call Image.resolveAssetSource with images included in the asset registry'
);
}

const asset = getAssetByID(source);
const uri = resolveAssetUri(source);

if (!asset || !uri) {
throw new Error(
'Unable to find requested resource in asset registry - ' + source
);
}

return {
height: asset.height,
width: asset.width,
uri,
scale: asset.scales[0]
};
};

const styles = StyleSheet.create({
root: {
flexBasis: 'auto',
Expand Down