diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b74c8..c7e9ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.0.0-rc.9 +- 修复Resource类型$r(变量无法)加载 +- 成功回调增加图片格式 +- Image组件增加onComplete回调 +- 修复404链接无返回错误信息 + ## 3.0.0-rc.8 - svg解码单位改为px - 修复预加载接口preLoadCache传ImageKnifeOption失效 diff --git a/entry/src/main/ets/pages/LoadStatePage.ets b/entry/src/main/ets/pages/LoadStatePage.ets index f5484b1..be2214c 100644 --- a/entry/src/main/ets/pages/LoadStatePage.ets +++ b/entry/src/main/ets/pages/LoadStatePage.ets @@ -38,6 +38,7 @@ struct LoadStatePage { } @State currentWidth: number = 200 @State currentHeight: number = 200 + @State typeValue: string = "" build() { Column() { Text('测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存') @@ -58,10 +59,11 @@ struct LoadStatePage { onLoadFailed: (err) => { console.error("Load Failed Reason: " + err + " cost " + (new Date().getTime() - this.starTime) + " milliseconds"); }, - onLoadSuccess: (data,width,height) => { + onLoadSuccess: (data,imageData) => { console.info("Load Successful: cost " + (new Date().getTime() - this.starTime) + " milliseconds"); - this.currentWidth = width! - this.currentHeight = height! + this.currentWidth = imageData.imageWidth! + this.currentHeight = imageData.imageHeight! + this.typeValue = imageData.type return data; }, }, @@ -70,7 +72,7 @@ struct LoadStatePage { }) } .margin({ top: 20 }) - + Text(this.typeValue) ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth) .margin({ top: 20 }) diff --git a/library/oh-package.json5 b/library/oh-package.json5 index c206a0f..d3f7e54 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-tpc/ImageKnife", "type": "module", - "version": "3.0.0-rc.8", + "version": "3.0.0-rc.9", "dependencies": { "@ohos/gpu_transform": "^1.0.2" }, diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 14dc829..136e931 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -82,7 +82,7 @@ export class ImageKnifeDispatcher { request.requestState = ImageKnifeRequestState.COMPLETE // 回调请求开结束 if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) { - request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source,memoryCache.imageWidth,memoryCache.imageHeight) + request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source,memoryCache) LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadSuccess:" + request.imageKnifeOption.loadSrc) } } else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) { @@ -272,7 +272,8 @@ export class ImageKnifeDispatcher { let ImageKnifeData: ImageKnifeData = { source: pixelmap!, imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width, - imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height + imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height, + type:requestJobResult.type }; // 保存内存缓存 @@ -305,7 +306,7 @@ export class ImageKnifeDispatcher { if (requestWithSource.request.imageKnifeOption.onLoadListener && requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess) { // 回调请求成功 - requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData.imageWidth,ImageKnifeData.imageHeight); + requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData); LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc) } } else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) { @@ -447,6 +448,8 @@ async function requestJob(request: RequestJobRequest, requestList?: List { if (data == 200) { resBuf = combineArrayBuffers(arrayBuffers) + } else { + loadError = "HttpDownloadClient has error, http code =" + JSON.stringify(data) } }).catch((err: Error) => { loadError = err.message; @@ -501,16 +504,21 @@ async function requestJob(request: RequestJobRequest, requestList?: List; - // 自定义缓存关键字 signature?: string; - // 主图填充效果 objectFit?: ImageFit - // 占位图填充效果 placeholderObjectFit?: ImageFit - // 错误图填充效果 errorholderObjectFit?: ImageFit - customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise - border?: BorderOptions // 缓存策略 writeCacheStrategy?: CacheStrategy // 仅使用缓存加载数据 onlyRetrieveFromCache?: boolean = false; - - priority? : taskpool.Priority = taskpool.Priority.LOW - + priority?: taskpool.Priority = taskpool.Priority.LOW context?: common.UIAbilityContext; - - progressListener?: (progress: number)=>void; - + progressListener?: (progress: number) => void; transformation?: PixelMapTransformation onLoadListener?: OnLoadCallBack | undefined; + omComplete?: (event:EventImage| undefined) => void constructor() { @@ -72,8 +75,10 @@ export class ImageKnifeOption { export interface OnLoadCallBack { // 请求开始 onLoadStart?: () => void; + // 请求成功 - onLoadSuccess?: (data: string | PixelMap | undefined,width?:number,height?:number) => void; + onLoadSuccess?: (data: string | PixelMap | undefined, ImageKnifeData:ImageKnifeData) => void; + // 请求结束 onLoadFailed?: (err: string) => void; } \ No newline at end of file diff --git a/library/src/main/ets/components/ImageKnifeComponent.ets b/library/src/main/ets/components/ImageKnifeComponent.ets index 88d2637..371aeec 100644 --- a/library/src/main/ets/components/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/ImageKnifeComponent.ets @@ -83,6 +83,7 @@ export struct ImageKnifeComponent { .border(this.imageKnifeOption.border) .syncLoad(this.syncLoad) .draggable(false) + .onComplete(this.imageKnifeOption.omComplete) .onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => { this.currentWidth = newValue.width as number this.currentHeight = newValue.height as number diff --git a/library/src/main/ets/model/ImageKnifeData.ets b/library/src/main/ets/model/ImageKnifeData.ets index a37f709..af48537 100644 --- a/library/src/main/ets/model/ImageKnifeData.ets +++ b/library/src/main/ets/model/ImageKnifeData.ets @@ -22,7 +22,8 @@ import { Size } from '@kit.ArkUI' export interface ImageKnifeData { source: PixelMap | string, imageWidth: number, - imageHeight: number + imageHeight: number, + type?:string } /** @@ -60,7 +61,8 @@ export interface RequestJobResult { bufferSize: number fileKey: string loadFail?: string, - size?:Size + size?:Size, + type?:string } /**