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 StyleSheetPropType = require('StyleSheetPropType');
|
||||||
var View = require('View');
|
var View = require('View');
|
||||||
|
|
||||||
|
var emptyFunction = require('emptyFunction');
|
||||||
var flattenStyle = require('flattenStyle');
|
var flattenStyle = require('flattenStyle');
|
||||||
var merge = require('merge');
|
var merge = require('merge');
|
||||||
var requireNativeComponent = require('requireNativeComponent');
|
var requireNativeComponent = require('requireNativeComponent');
|
||||||
|
@ -140,6 +141,12 @@ var Image = React.createClass({
|
||||||
success: (width: number, height: number) => void,
|
success: (width: number, height: number) => void,
|
||||||
failure: (error: any) => 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)
|
return ImageLoader.getSize(url)
|
||||||
.then(function(sizes) {
|
.then(function(sizes) {
|
||||||
success(sizes.width, sizes.height);
|
success(sizes.width, sizes.height);
|
||||||
|
@ -154,6 +161,10 @@ var Image = React.createClass({
|
||||||
* cache
|
* cache
|
||||||
*/
|
*/
|
||||||
prefetch(url: string, callback: ?Function) {
|
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();
|
const requestId = generateRequestId();
|
||||||
callback && callback(requestId);
|
callback && callback(requestId);
|
||||||
return ImageLoader.prefetchImage(url, requestId);
|
return ImageLoader.prefetchImage(url, requestId);
|
||||||
|
@ -163,7 +174,7 @@ var Image = React.createClass({
|
||||||
* Abort prefetch request
|
* Abort prefetch request
|
||||||
*/
|
*/
|
||||||
abortPrefetch(requestId: number) {
|
abortPrefetch(requestId: number) {
|
||||||
ImageLoader.abortRequest(requestId);
|
ImageLoader && ImageLoader.abortRequest(requestId);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue