From 1a55d5188fe0c2d89a74406ea7abc3173574c7e4 Mon Sep 17 00:00:00 2001 From: zgf Date: Fri, 17 May 2024 15:20:17 +0800 Subject: [PATCH] =?UTF-8?q?Watch=E7=9B=91=E5=90=ACimageKnifeOption?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=94=B9=E4=B8=BA@State,=E5=AF=B9imageKnifeO?= =?UTF-8?q?ption=E5=AF=B9=E8=B1=A1=E9=87=8C=E9=9D=A2=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 1 + build-profile.json5 | 4 +-- library/src/main/ets/ImageKnifeOption.ets | 26 +++++++++++-------- .../ets/components/ImageKnifeComponent.ets | 13 +++++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3715d2f..69bf3b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.0.0-rc.5 - 图片加载事件增加请求开始的回调,以及修复有缓存时,没有回调的bug - 修复对已销毁组件不再下发请求的逻辑 +- Watch监听imageKnifeOption属性改为@State,对imageKnifeOption对象里面内容进行监听 ## 3.0.0-rc.4 - 支持hsp多包图片资源 diff --git a/build-profile.json5 b/build-profile.json5 index d2d4041..1d9a371 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -7,8 +7,8 @@ { "name": "default", "signingConfig": "default", - "compileSdkVersion": "4.1.0(11)", - "compatibleSdkVersion": "4.1.0(11)", + "compileSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", } ], diff --git a/library/src/main/ets/ImageKnifeOption.ets b/library/src/main/ets/ImageKnifeOption.ets index 1531896..7cd5366 100644 --- a/library/src/main/ets/ImageKnifeOption.ets +++ b/library/src/main/ets/ImageKnifeOption.ets @@ -23,42 +23,46 @@ export interface HeaderOptions { } @Observed export class ImageKnifeOption { + @Track // 主图资源 loadSrc: string | PixelMap | Resource = ""; // 占位图 placeholderSrc?: string | PixelMap | Resource; // 失败占位图 errorholderSrc?: string | PixelMap | Resource; - + @Track headerOption?: Array; - + @Track // 自定义缓存关键字 signature?: string; - + @Track // 主图填充效果 objectFit?: ImageFit - + @Track // 占位图填充效果 placeholderObjectFit?: ImageFit - + @Track // 错误图填充效果 errorholderObjectFit?: ImageFit - + @Track customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise - + @Track border?: BorderOptions // 缓存策略 + @Track writeCacheStrategy?: CacheStrategy // 仅使用缓存加载数据 + @Track onlyRetrieveFromCache?: boolean = false; - + @Track priority? : taskpool.Priority = taskpool.Priority.LOW - + @Track context?: common.UIAbilityContext; - + @Track progressListener?: (progress: number)=>void; - + @Track transformation?: PixelMapTransformation + @Track onLoadListener?: OnLoadCallBack | undefined; constructor() { diff --git a/library/src/main/ets/components/ImageKnifeComponent.ets b/library/src/main/ets/components/ImageKnifeComponent.ets index 2d8c3bd..7fee453 100644 --- a/library/src/main/ets/components/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/ImageKnifeComponent.ets @@ -21,7 +21,7 @@ import { ImageKnifeRequestSource } from '../model/ImageKnifeData'; @Component export struct ImageKnifeComponent { - @Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption; + @Watch('watchImageKnifeOption') @State imageKnifeOption: ImageKnifeOption = new ImageKnifeOption(); @State pixelMap: PixelMap | string | undefined = undefined @State adaptiveWidth: Length = '100%' @State adaptiveHeight: Length = '100%' @@ -53,7 +53,15 @@ export struct ImageKnifeComponent { this.request = undefined } } - + aboutToReuse(params: ESObject): void { + this.imageKnifeOption = params.imageKnifeOption + if (this.request !== undefined) { + this.request.requestState = ImageKnifeRequestState.DESTROY + } + this.request = undefined + this.componentVersion++ + ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight)) + } aboutToRecycle() { if (this.request !== undefined) { this.request.requestState = ImageKnifeRequestState.DESTROY @@ -90,7 +98,6 @@ export struct ImageKnifeComponent { this.request.requestState = ImageKnifeRequestState.DESTROY } this.request = undefined - this.componentVersion++ ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight)) }