safeguard for missing ImageLoader native module
Differential Revision: D3604593 fbshipit-source-id: f7f77bfb01ca51e660b68945ff7271a492df1bcb
This commit is contained in:
parent
55638f804d
commit
32a717892c
|
@ -23,6 +23,7 @@ var StyleSheet = require('StyleSheet');
|
|||
var StyleSheetPropType = require('StyleSheetPropType');
|
||||
var View = require('View');
|
||||
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var flattenStyle = require('flattenStyle');
|
||||
var merge = require('merge');
|
||||
var requireNativeComponent = require('requireNativeComponent');
|
||||
|
@ -140,6 +141,12 @@ var Image = React.createClass({
|
|||
success: (width: number, height: number) => void,
|
||||
failure: (error: any) => void,
|
||||
) {
|
||||
if (!ImageLoader) {
|
||||
failure ?
|
||||
failure() :
|
||||
console.warn('ImageLoader native module is missing, image size cannot be fetched.');
|
||||
return;
|
||||
}
|
||||
return ImageLoader.getSize(url)
|
||||
.then(function(sizes) {
|
||||
success(sizes.width, sizes.height);
|
||||
|
@ -154,6 +161,10 @@ var Image = React.createClass({
|
|||
* cache
|
||||
*/
|
||||
prefetch(url: string, callback: ?Function) {
|
||||
if (!ImageLoader) {
|
||||
console.warn('ImageLoader native module is missing, image will not preload.');
|
||||
return new Promise(emptyFunction);
|
||||
}
|
||||
const requestId = generateRequestId();
|
||||
callback && callback(requestId);
|
||||
return ImageLoader.prefetchImage(url, requestId);
|
||||
|
@ -163,7 +174,7 @@ var Image = React.createClass({
|
|||
* Abort prefetch request
|
||||
*/
|
||||
abortPrefetch(requestId: number) {
|
||||
ImageLoader.abortRequest(requestId);
|
||||
ImageLoader && ImageLoader.abortRequest(requestId);
|
||||
},
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue