From 48b425109afdbcfb964a72c1eea725625102775f Mon Sep 17 00:00:00 2001 From: zgf Date: Wed, 14 Aug 2024 17:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8A=A8=E5=9B=BE=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=96=B0=E5=A2=9E=E4=BA=8B=E4=BB=B6=E5=92=8C=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BC=93=E5=AD=98=E6=95=B0=E9=87=8F=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E5=80=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 4 ++++ README.md | 17 +++++++++------ .../src/main/ets/pages/ImageAnimatorPage.ets | 6 ++++++ library/oh-package.json5 | 2 +- library/src/main/ets/ImageKnifeOption.ets | 21 ++++++++++++++++++- .../ImageKnifeAnimatorComponent.ets | 5 +++++ library/src/main/ets/utils/FileCache.ets | 6 +++--- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07dce31..2e4537e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.0-rc.1 +- ImageKnifeAnimatorComponent新增开始、结束、暂停的回调事件 +- 文件缓存数量负数和超过INT最大值时默认为INT最大值 + ## 3.1.0-rc.0 - ComponentV2装饰器适配 - imageKnifeOption={...}用法改为new ImageKnifeOption({...}) diff --git a/README.md b/README.md index b616b70..4eb4dc8 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ ImageKnifeComponent({ ImageKnifeOption: new ImageKnifeOption( }) }).width(100).height(100) ``` -#### 9.ImageKnifeComponent - syncLoad +#### 9.ImageKnifeComponent - syncLoad 设置是否同步加载图片,默认是异步加载。建议加载尺寸较小的本地图片时将syncLoad设为true,因为耗时较短,在主线程上执行即可 ``` ImageKnifeComponent({ @@ -273,11 +273,16 @@ ImageKnifeAnimatorComponent({ | ImageKnifeAnimatorComponent | ImageKnifeOption、AnimatorOption | 动图控制组件 | ### AnimatorOption参数列表 -| 参数名称 | 入参内容 | 功能简介 | -|-----------------------|-------------------------------------------------------|----------| -| state | AnimationStatus | 播放状态(可选) | -| iterations | number | 播放次数(可选) | -| reverse | boolean | 播放顺序(可选) | +| 参数名称 | 入参内容 | 功能简介 | +|------------|-----------------|----------| +| state | AnimationStatus | 播放状态(可选) | +| iterations | number | 播放次数(可选) | +| reverse | boolean | 播放顺序(可选) | +| onStart | ()=>void | 动画开始播放时触发(可选) | +| onFinish | ()=>void | 动画播放完成时或者停止播放时触发(可选) | +| onPause | ()=>void | 动画暂停播放时触发(可选) | +| onCancel | ()=>void | 动画返回最初状态时触发(可选) | +| onRepeat | ()=>void | 动画重复播放时触发(可选) | ### ImageKnifeOption参数列表 diff --git a/entry/src/main/ets/pages/ImageAnimatorPage.ets b/entry/src/main/ets/pages/ImageAnimatorPage.ets index bd67974..4efadcb 100644 --- a/entry/src/main/ets/pages/ImageAnimatorPage.ets +++ b/entry/src/main/ets/pages/ImageAnimatorPage.ets @@ -33,9 +33,15 @@ struct ImageAnimatorPage { Flex(){ Button("播放").onClick(()=>{ this.animatorOption.state = AnimationStatus.Running + this.animatorOption.onStart = ()=>{ + console.log("ImageKnifeAnimatorComponent animatorOption onStart") + } }) Button("暂停").onClick(()=>{ this.animatorOption.state = AnimationStatus.Paused + this.animatorOption.onFinish = ()=>{ + console.log("ImageKnifeAnimatorComponent animatorOption onFinish") + } }) Button("停止").onClick(()=>{ this.animatorOption.state = AnimationStatus.Stopped diff --git a/library/oh-package.json5 b/library/oh-package.json5 index 67af1d6..5922ecf 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.1-rc.2", + "version": "3.1.0-rc.1", "dependencies": { "@ohos/gpu_transform": "^1.0.2" }, diff --git a/library/src/main/ets/ImageKnifeOption.ets b/library/src/main/ets/ImageKnifeOption.ets index 68b23da..3a9bf6f 100644 --- a/library/src/main/ets/ImageKnifeOption.ets +++ b/library/src/main/ets/ImageKnifeOption.ets @@ -26,6 +26,11 @@ interface AnimatorType { state?: AnimationStatus iterations?: number reverse?: boolean + onStart?:()=>void + onFinish?:()=>void + onPause?:()=>void + onCancel?:()=>void + onRepeat?:()=>void } @ObservedV2 export class AnimatorOption { @@ -35,11 +40,25 @@ export class AnimatorOption { iterations?: number = -1 @Trace reverse?: boolean = false - + @Trace + onStart?:()=>void + @Trace + onFinish?:()=>void + @Trace + onPause?:()=>void + @Trace + onCancel?:()=>void + @Trace + onRepeat?:()=>void constructor(option?:AnimatorType) { this.state = option?.state this.iterations = option?.iterations this.reverse = option?.reverse + this.onStart = option?.onStart + this.onFinish = option?.onFinish + this.onPause = option?.onPause + this.onCancel = option?.onCancel + this.onRepeat = option?.onRepeat } } interface ImageOption { diff --git a/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets b/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets index e34e350..4417ff1 100644 --- a/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets +++ b/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets @@ -88,6 +88,11 @@ export struct ImageKnifeAnimatorComponent { } } }) + .onStart(this.animatorOption.onStart) + .onFinish(this.animatorOption.onFinish) + .onPause(this.animatorOption.onPause) + .onCancel(this.animatorOption.onCancel) + .onRepeat(this.animatorOption.onRepeat) } getCurrentContext(): common.UIAbilityContext { diff --git a/library/src/main/ets/utils/FileCache.ets b/library/src/main/ets/utils/FileCache.ets index 8c47562..f4e5fcc 100644 --- a/library/src/main/ets/utils/FileCache.ets +++ b/library/src/main/ets/utils/FileCache.ets @@ -18,7 +18,7 @@ import fs from '@ohos.file.fs'; import { LogUtil } from './LogUtil'; import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'; - +const INT_MAX = 2147483647 /** * 二级文件缓存 * 主线程通过lruCache管理缓存大小 @@ -34,12 +34,12 @@ export class FileCache { private isInited: boolean = false private context?: Context readonly defaultMaxSize: number = 512; - readonly defaultSize: number = 128; + readonly defaultSize: number = INT_MAX; readonly defaultMaxMemorySize: number = 512 * 1024 * 1024; readonly defaultMemorySize: number = 128 * 1024 * 1024; constructor(context: Context, size: number, memory: number) { - if (size <= 0) { + if (size <= 0 || size > INT_MAX) { size = this.defaultSize } if (memory <= 0 || memory > this.defaultMaxMemorySize) {