diff --git a/README.md b/README.md index 81b77b7..509435a 100644 --- a/README.md +++ b/README.md @@ -234,10 +234,13 @@ ImageKnifeComponent({ ImageKnifeOption: onLoadFailed: (err) => { console.error("Load Failed Reason: " + err + " cost " + (new Date().getTime() - this.starTime) + " milliseconds"); }, - onLoadSuccess: (data) => { + onLoadSuccess: (data, imageData) => { console.info("Load Successful: cost " + (new Date().getTime() - this.starTime) + " milliseconds"); return data; }, + onLoadCancel(err){ + console.info(err) + } } } }).width(100).height(100) diff --git a/entry/src/main/ets/pages/LoadStatePage.ets b/entry/src/main/ets/pages/LoadStatePage.ets index 291648c..e863e7c 100644 --- a/entry/src/main/ets/pages/LoadStatePage.ets +++ b/entry/src/main/ets/pages/LoadStatePage.ets @@ -69,7 +69,7 @@ struct LoadStatePage { }, border: { radius: 50 }, onComplete:(event)=>{ - console.error("Load onComplete width:"+event?width,"height:"+event?height,"componentWidth:"+event?.componentWidth,"componentHeight:"+event?.componentHeight); + console.error("Load onComplete width:"+event?.width , " height:"+event?.height , " componentWidth:"+event?.componentWidth," componentHeight:" + event?.componentHeight); } } }) diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index b7d537b..279706d 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -313,12 +313,9 @@ export class ImageKnifeDispatcher { requestWithSource.request.requestState = ImageKnifeRequestState.ERROR; } } else { - if (requestWithSource.source == ImageKnifeRequestSource.SRC) { - if (requestWithSource.request.imageKnifeOption.onLoadListener && - requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel) { + if (requestWithSource.source == ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadCancel) { // 回调请求成功 - requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel("component has destroyed"); - } + requestWithSource.request.imageKnifeOption.onLoadListener.onLoadCancel("component has destroyed") } } }); @@ -343,6 +340,8 @@ export class ImageKnifeDispatcher { this.executeJob(request) LogUtil.log("ImageKnife_DataTime_dispatchNextJob.end:" + request.imageKnifeOption.loadSrc) break + }else if (request.requestState == ImageKnifeRequestState.DESTROY && request.imageKnifeOption.onLoadListener?.onLoadCancel) { + request.imageKnifeOption.onLoadListener.onLoadCancel("component has destroyed") } } }