From fde7c354494c6f0749b7bb6c6b6585b03d34501f Mon Sep 17 00:00:00 2001 From: Adam Comella Date: Mon, 14 Nov 2016 21:01:02 -0800 Subject: [PATCH] Make resolveAssetSource public Summary: When building a native component which takes an image reference as a prop, `resolveAssetSource` needs to be called on the image reference. If this isn't done, the native component may receive the opaque type returned by `require` (e.g. `require('./foo.png')`) which is useless to the native component. `resolveAssetSource` is used by builtin components that take image references such as `Image`, `WebView` and `MapView`. This change makes `resolveAssetSource` public so that third-party native components can correctly handle image references. **Test plan (required)** Verified that `Image.resolveAssetSource` works in a test app. Also, my team is using this change in our app. Adam Comella Microsoft Corp. Closes https://github.com/facebook/react-native/pull/10904 Differential Revision: D4177803 Pulled By: ericvicenti fbshipit-source-id: ffc511b9340325f7d1111002309cd8558ab8e6b0 --- Libraries/Image/Image.android.js | 9 ++++++++- Libraries/Image/Image.ios.js | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Libraries/Image/Image.android.js b/Libraries/Image/Image.android.js index bd5b0bd16..c56fa2ce1 100644 --- a/Libraries/Image/Image.android.js +++ b/Libraries/Image/Image.android.js @@ -220,7 +220,14 @@ var Image = React.createClass({ */ async queryCache(urls: Array): Promise> { return await ImageLoader.queryCache(urls); - } + }, + + /** + * Resolves an asset reference into an object which has the properties `uri`, `width`, + * and `height`. The input may either be a number (opaque type returned by + * require('./foo.png')) or an `ImageSource` like { uri: '' } + */ + resolveAssetSource: resolveAssetSource, }, mixins: [NativeMethodsMixin], diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index 04c78d6cb..012aa09ad 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -317,6 +317,12 @@ const Image = React.createClass({ prefetch(url: string) { return ImageViewManager.prefetchImage(url); }, + /** + * Resolves an asset reference into an object which has the properties `uri`, `width`, + * and `height`. The input may either be a number (opaque type returned by + * require('./foo.png')) or an `ImageSource` like { uri: '' } + */ + resolveAssetSource: resolveAssetSource, }, mixins: [NativeMethodsMixin],