diff --git a/packages/react-native-web/src/exports/Image/index.js b/packages/react-native-web/src/exports/Image/index.js index f99faa7ec..764b694ce 100644 --- a/packages/react-native-web/src/exports/Image/index.js +++ b/packages/react-native-web/src/exports/Image/index.js @@ -167,6 +167,12 @@ interface ImageStatics { failure: () => void ) => void; prefetch: (uri: string) => Promise; + resolveAssetSource: (source: $PropertyType) => { + height: ?number, + width: ?number, + scale: number, + uri: string + }; queryCache: ( uris: Array ) => Promise<{| [uri: string]: 'disk/memory' |}>; @@ -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',