mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08:00
[fix] limit Image loader deferral to 1000ms
This patch introduces a limit on how long image loading is deferred, and mitigates an issue with lengthy delays to 'requestIdleCallback' in the Chrome browser. Fix #759
This commit is contained in:
@@ -87,6 +87,9 @@ type State = {
|
||||
shouldDisplaySource: boolean
|
||||
};
|
||||
|
||||
const getAssetTimeout = source =>
|
||||
typeof source === 'object' && source.timeout ? source.timeout : 1000;
|
||||
|
||||
class Image extends Component<*, State> {
|
||||
static displayName = 'Image';
|
||||
|
||||
@@ -246,12 +249,16 @@ class Image extends Component<*, State> {
|
||||
}
|
||||
|
||||
_createImageLoader() {
|
||||
const { source } = this.props;
|
||||
this._destroyImageLoader();
|
||||
this._loadRequest = requestIdleCallback(() => {
|
||||
const uri = resolveAssetSource(this.props.source);
|
||||
this._imageRequestId = ImageLoader.load(uri, this._onLoad, this._onError);
|
||||
this._onLoadStart();
|
||||
});
|
||||
this._loadRequest = requestIdleCallback(
|
||||
() => {
|
||||
const uri = resolveAssetSource(source);
|
||||
this._imageRequestId = ImageLoader.load(uri, this._onLoad, this._onError);
|
||||
this._onLoadStart();
|
||||
},
|
||||
{ timeout: getAssetTimeout(source) }
|
||||
);
|
||||
}
|
||||
|
||||
_destroyImageLoader() {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
||||
|
||||
const _requestIdleCallback = function(cb: Function) {
|
||||
const _requestIdleCallback = function(cb: Function, options: Object) {
|
||||
return setTimeout(() => {
|
||||
const start = Date.now();
|
||||
cb({
|
||||
|
||||
Reference in New Issue
Block a user