From f0f513193272587f2b2bb69346257c90b222b85a Mon Sep 17 00:00:00 2001 From: zgf Date: Tue, 4 Jun 2024 15:46:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A7=E5=88=B6=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=9B=BE=E7=BB=84=E4=BB=B6ImageKnifeAnimatorComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 1 + .../main/ets/common/CustomEngineKeyImpl.ets | 8 +- .../src/main/ets/pages/ImageAnimatorPage.ets | 41 +++++ entry/src/main/ets/pages/Index.ets | 10 +- .../resources/base/profile/main_pages.json | 3 +- library/index.ets | 4 +- library/src/main/ets/ImageKnife.ets | 4 +- library/src/main/ets/ImageKnifeDispatcher.ets | 88 +++++++--- library/src/main/ets/ImageKnifeOption.ets | 9 + library/src/main/ets/ImageKnifeRequest.ets | 2 +- .../ImageKnifeAnimatorComponent.ets | 163 ++++++++++++++++++ library/src/main/ets/key/DefaultEngineKey.ets | 8 +- library/src/main/ets/key/IEngineKey.ets | 4 +- library/src/main/ets/model/ImageKnifeData.ets | 8 +- sharedlibrary/Index.ets | 4 + 15 files changed, 317 insertions(+), 40 deletions(-) create mode 100644 entry/src/main/ets/pages/ImageAnimatorPage.ets create mode 100644 library/src/main/ets/components/ImageKnifeAnimatorComponent.ets diff --git a/CHANGELOG.md b/CHANGELOG.md index dcad63b..77fbaf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 3.0.0-rc.7 - 修复成功回调获取不到宽高 +- 新增控制动态图组件ImageKnifeAnimatorComponent ## 3.0.0-rc.6 - 支持多种组合变换 diff --git a/entry/src/main/ets/common/CustomEngineKeyImpl.ets b/entry/src/main/ets/common/CustomEngineKeyImpl.ets index 4354e1c..84406b5 100644 --- a/entry/src/main/ets/common/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/common/CustomEngineKeyImpl.ets @@ -19,8 +19,8 @@ import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKni export class CustomEngineKeyImpl implements IEngineKey { // 生成内存缓存key generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, - imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string { - let key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + imageKnifeOption: ImageKnifeOption,isAnimator?:boolean, width?: number, height?: number): string { + let key = (isAnimator == undefined ? "loadSrc=" : "Animator==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" if (requestSource === ImageKnifeRequestSource.SRC) { if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") { key += "signature=" + imageKnifeOption.signature + ";" @@ -33,8 +33,8 @@ export class CustomEngineKeyImpl implements IEngineKey { } // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string,isAnimator?:boolean): string { + let src = (isAnimator == undefined ? "loadSrc=" : "Animator==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" if (signature !== undefined && signature !== "") { src += "signature=" + signature + ";" } diff --git a/entry/src/main/ets/pages/ImageAnimatorPage.ets b/entry/src/main/ets/pages/ImageAnimatorPage.ets new file mode 100644 index 0000000..bde0508 --- /dev/null +++ b/entry/src/main/ets/pages/ImageAnimatorPage.ets @@ -0,0 +1,41 @@ +import { AnimatorOption, ImageKnifeAnimatorComponent } from "@ohos/libraryimageknife" + +@Entry +@Component +struct ImageAnimatorPage { + @State animatorOption: AnimatorOption = { + state: AnimationStatus.Running, + iterations: -1 + } + build() { + Column(){ + Flex(){ + Button("播放").onClick(()=>{ + this.animatorOption.state = AnimationStatus.Running + }) + Button("暂停").onClick(()=>{ + this.animatorOption.state = AnimationStatus.Paused + }) + Button("停止").onClick(()=>{ + this.animatorOption.state = AnimationStatus.Stopped + }) + Button("无限循环").onClick(()=>{ + this.animatorOption.iterations = -1 + }) + Button("播放一次").onClick(()=>{ + this.animatorOption.iterations = 1 + }) + Button("播放两次").onClick(()=>{ + this.animatorOption.iterations = 2 + }) + } + ImageKnifeAnimatorComponent({ + imageKnifeOption:{ + loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658", + placeholderSrc:$r('app.media.loading'), + errorholderSrc:$r('app.media.failed') + },animatorOption:this.animatorOption + }).width(300).height(300).backgroundColor(Color.Orange).margin({top:30}) + }.width("100%").height("100%") + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index f6508f2..8383f53 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -26,13 +26,19 @@ struct Index { build() { Scroll(){ Column() { - Button("测试HSP场景预加载").onClick(()=>{ + Button("测试ImageAnimator组件").onClick(()=>{ + router.push({ + uri: 'pages/ImageAnimatorPage', + + }); + }) + Button("测试HSP场景预加载").margin({top:10}).onClick(()=>{ router.push({ uri: 'pages/TestHspPreLoadImage', }); }) - Button("单个图片使用").onClick(()=>{ + Button("单个图片使用").margin({top:10}).onClick(()=>{ router.push({ uri: 'pages/SingleImage', diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index cd3a400..c721a68 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -17,6 +17,7 @@ "pages/TestWriteCacheStage", "pages/LoadStatePage", "pages/TestHspPreLoadImage", - "pages/TestRemoveCache" + "pages/TestRemoveCache", + "pages/ImageAnimatorPage" ] } \ No newline at end of file diff --git a/library/index.ets b/library/index.ets index 1b690d5..8a6ae12 100644 --- a/library/index.ets +++ b/library/index.ets @@ -1,8 +1,10 @@ export { ImageKnifeComponent } from './src/main/ets/components/ImageKnifeComponent' +export { ImageKnifeAnimatorComponent } from './src/main/ets/components/ImageKnifeAnimatorComponent' + export { ImageKnife } from './src/main/ets/ImageKnife' -export { ImageKnifeOption } from './src/main/ets/ImageKnifeOption' +export { ImageKnifeOption,AnimatorOption } from './src/main/ets/ImageKnifeOption' export { ImageKnifeRequest } from './src/main/ets/ImageKnifeRequest' diff --git a/library/src/main/ets/ImageKnife.ets b/library/src/main/ets/ImageKnife.ets index 19b4d08..fe26c44 100644 --- a/library/src/main/ets/ImageKnife.ets +++ b/library/src/main/ets/ImageKnife.ets @@ -349,12 +349,12 @@ export class ImageKnife { return undefined } - async execute(request: ImageKnifeRequest): Promise { + async execute(request: ImageKnifeRequest,isAnimator?: boolean): Promise { LogUtil.log("ImageKnife_DataTime_execute.start:"+request.imageKnifeOption.loadSrc) if (this.headerMap.size > 0) { request.addHeaderMap(this.headerMap) } - this.dispatcher.enqueue(request) + this.dispatcher.enqueue(request,isAnimator) LogUtil.log("ImageKnife_DataTime_execute.end:"+request.imageKnifeOption.loadSrc) } diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 9eb9609..9b39a83 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -51,7 +51,7 @@ export class ImageKnifeDispatcher { // 开发者可配置全局缓存 private engineKey: IEngineKey = new DefaultEngineKey(); - showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): boolean { + showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?: boolean): boolean { LogUtil.log("ImageKnife_DataTime_showFromMemomry.start:" + request.imageKnifeOption.loadSrc) let memoryCache: ImageKnifeData | undefined; if ((typeof (request.imageKnifeOption.loadSrc as image.PixelMap).isEditable) == 'boolean') { @@ -62,7 +62,7 @@ export class ImageKnifeDispatcher { } } else { memoryCache = ImageKnife.getInstance() - .loadFromMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, request.imageKnifeOption)); + .loadFromMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, request.imageKnifeOption,isAnimator)); } @@ -75,7 +75,7 @@ export class ImageKnifeDispatcher { LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadStart:" + request.imageKnifeOption.loadSrc) } LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.start:" + request.imageKnifeOption.loadSrc) - request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source, requestSource) + request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source, requestSource,memoryCache.imageAnimator) LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.end:" + request.imageKnifeOption.loadSrc) if (requestSource == ImageKnifeRequestSource.SRC) { @@ -97,10 +97,10 @@ export class ImageKnifeDispatcher { } - enqueue(request: ImageKnifeRequest): void { + enqueue(request: ImageKnifeRequest,isAnimator?: boolean): void { //1.内存有的话直接渲染 - if (this.showFromMemomry(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC)) { + if (this.showFromMemomry(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC,isAnimator)) { return } @@ -109,10 +109,10 @@ export class ImageKnifeDispatcher { this.jobQueue.add(request) return } - this.executeJob(request) + this.executeJob(request,isAnimator) } - executeJob(request: ImageKnifeRequest): void { + executeJob(request: ImageKnifeRequest,isAnimator?: boolean): void { LogUtil.log("ImageKnife_DataTime_executeJob.start:" + request.imageKnifeOption.loadSrc) // 加载占位符 if (request.imageKnifeOption.placeholderSrc !== undefined) { @@ -122,16 +122,16 @@ export class ImageKnifeDispatcher { } // 加载主图 - this.getAndShowImage(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC) + this.getAndShowImage(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC,isAnimator) LogUtil.log("ImageKnife_DataTime_executeJob.end:" + request.imageKnifeOption.loadSrc) } /** * 获取和显示图片 */ - getAndShowImage(currentRequest: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): void { + getAndShowImage(currentRequest: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?: boolean): void { LogUtil.log("ImageKnife_DataTime_getAndShowImage.start:" + currentRequest.imageKnifeOption.loadSrc) - let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption) + let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption,isAnimator) let requestList: List | undefined = this.executingJobMap.get(memoryKey) if (requestList == undefined) { requestList = new List() @@ -171,7 +171,8 @@ export class ImageKnifeDispatcher { signature: currentRequest.imageKnifeOption.signature, requestSource: requestSource, isWatchProgress: isWatchProgress, - memoryKey: memoryKey + memoryKey: memoryKey, + isAnimator:isAnimator } @@ -188,7 +189,7 @@ export class ImageKnifeDispatcher { LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.start:" + currentRequest.imageKnifeOption.loadSrc) taskpool.execute(task).then((res: Object) => { - this.doTaskCallback(res as RequestJobResult | undefined, requestList!, currentRequest, memoryKey, imageSrc, requestSource); + this.doTaskCallback(res as RequestJobResult | undefined, requestList!, currentRequest, memoryKey, imageSrc, requestSource,isAnimator); if (isWatchProgress){ emitter.off(Constants.PROGRESS_EMITTER + memoryKey) } @@ -230,7 +231,7 @@ export class ImageKnifeDispatcher { } private doTaskCallback(requestJobResult: RequestJobResult | undefined, requestList: List , - currentRequest: ImageKnifeRequest, memoryKey: string, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource):void { + currentRequest: ImageKnifeRequest, memoryKey: string, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource,isAnimator?:boolean):void { LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.start:"+currentRequest.imageKnifeOption.loadSrc) if (requestJobResult === undefined){ return @@ -270,12 +271,22 @@ export class ImageKnifeDispatcher { imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width, imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height }; + if(requestJobResult.pixelMapList != undefined) { + let imageAnimator: Array = [] + requestJobResult.pixelMapList.forEach((item,index)=>{ + imageAnimator.push({ + src:requestJobResult.pixelMapList![index], + duration:requestJobResult.delayList![index] + }) + }) + ImageKnifeData.imageAnimator = imageAnimator + } // 保存内存缓存 if (currentRequest.imageKnifeOption.writeCacheStrategy !== CacheStrategy.File) { LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.start:"+currentRequest.imageKnifeOption.loadSrc) ImageKnife.getInstance() - .saveMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption), + .saveMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption,isAnimator), ImageKnifeData); LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.end:"+currentRequest.imageKnifeOption.loadSrc) } @@ -294,7 +305,7 @@ export class ImageKnifeDispatcher { requestWithSource.request.requestState === ImageKnifeRequestState.PROGRESS)) { LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.start:"+currentRequest.imageKnifeOption.loadSrc) requestWithSource.request.ImageKnifeRequestCallback.showPixelMap(requestWithSource.request.componentVersion, - ImageKnifeData.source, requestWithSource.source); + ImageKnifeData.source, requestWithSource.source,ImageKnifeData.imageAnimator); LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.end:"+currentRequest.imageKnifeOption.loadSrc) } @@ -370,7 +381,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List = [] + let delayList: Array = [] + await imageSource.createPixelMapList(decodingOptions).then(async (pixelList: Array) => { + //sdk的api接口发生变更:从.getDelayTime() 变为.getDelayTimeList() + await imageSource.getDelayTimeList().then(delayTimes => { + if (pixelList.length > 0) { + for (let i = 0; i < pixelList.length; i++) { + pixelMapList.push(pixelList[i]); + if (i < delayTimes.length) { + delayList.push(delayTimes[i]); + } else { + delayList.push(delayTimes[delayTimes.length - 1]) + } + } + imageSource.release(); + } + }) + }) + return { + pixelMap: "", + bufferSize: bufferSize, + fileKey: fileKey, + pixelMapList, + delayList + } + } else { + return { + pixelMap: undefined, + bufferSize: 0, + fileKey: '', + loadFail: "ImageKnifeAnimatorComponent组件仅支持动态图", + } + } + } if (typeValue === 'gif' || typeValue === 'webp') { let base64Help = new util.Base64Helper() @@ -523,11 +574,6 @@ async function requestJob(request: RequestJobRequest, requestList?: List void; + showPixelMap: (version: number, pixelMap: PixelMap | string , requestSource: ImageKnifeRequestSource,imageAnimator?: Array) => void; } diff --git a/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets b/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets new file mode 100644 index 0000000..9c9b4f8 --- /dev/null +++ b/library/src/main/ets/components/ImageKnifeAnimatorComponent.ets @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AnimatorOption, ImageKnifeOption } from '../ImageKnifeOption'; +import { ImageKnifeRequest, ImageKnifeRequestState } from '../ImageKnifeRequest'; +import common from '@ohos.app.ability.common'; +import { ImageKnife } from '../ImageKnife'; +import { LogUtil } from '../utils/LogUtil'; +import { ImageKnifeRequestSource } from '../model/ImageKnifeData'; + +@Component +export struct ImageKnifeAnimatorComponent { + @Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption; + @Watch('watchAnimatorOption') @State animatorOption: AnimatorOption = new AnimatorOption(); + @State pixelMap: PixelMap | string | undefined = undefined + @State imageAnimator: Array | undefined = undefined + @State state: AnimationStatus = AnimationStatus.Running + @State iterations: number = -1 + @State reverse: boolean = false + @State adaptiveWidth: Length = '100%' + @State adaptiveHeight: Length = '100%' + @State objectFit: ImageFit = ImageFit.Contain + private request: ImageKnifeRequest | undefined + private lastWidth: number = 0 + private lastHeight: number = 0 + private currentWidth: number = 0 + private currentHeight: number = 0 + private componentVersion: number = 0 + private currentContext: common.UIAbilityContext | undefined = undefined + + aboutToAppear(): void { + //闪动问题失效,注释相应代码后续修复 + // let memoryCache: ImageKnifeData | undefined = ImageKnife.getInstance() + // .loadFromMemoryCache(Tools.generateMemoryKey(this.ImageKnifeOption.loadSrc)) + // if (memoryCache !== undefined){ + // LogUtil.log("aboutToAppear load from memory cache for key = "+ Tools.generateMemoryKey(this.ImageKnifeOption.loadSrc)) + // //画主图 + // this.pixelMap = memoryCache.source; + // }else { + // } + this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit + } + + aboutToDisappear(): void { + if (this.request !== undefined) { + this.request.requestState = ImageKnifeRequestState.DESTROY + this.request = undefined + } + } + + aboutToRecycle() { + if (this.request !== undefined) { + this.request.requestState = ImageKnifeRequestState.DESTROY + this.request = undefined + } + this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit + } + + build() { + ImageAnimator() + .images(this.imageAnimator) + .width(this.adaptiveWidth) + .height(this.adaptiveHeight) + .border(this.imageKnifeOption.border) + .state(this.state) + .iterations(this.iterations) + .reverse(this.reverse) + .onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => { + this.currentWidth = newValue.width as number + this.currentHeight = newValue.height as number + this.lastWidth = oldValue.width as number + this.lastHeight = oldValue.height as number + if (this.currentWidth <= 0 || this.currentHeight <= 0) { + // 存在宽或者高为0,此次重回无意义,无需进行request请求 + } else { + // 前提:宽高值均有效,值>0. 条件1:当前宽高与上一次宽高不同 条件2:当前是第一次绘制 + if (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) { + LogUtil.log("execute request:width=" + this.currentWidth + " height= " + this.currentHeight) + ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight),true) + } + } + }) + } + + watchAnimatorOption(){ + if(this.animatorOption.state != undefined) { + this.state = this.animatorOption.state + } + if(this.animatorOption.iterations != undefined) { + this.iterations = this.animatorOption.iterations + } + if(this.animatorOption.reverse != undefined) { + this.reverse = this.animatorOption.reverse + } + } + + watchImageKnifeOption() { + if (this.request !== undefined) { + this.request.requestState = ImageKnifeRequestState.DESTROY + } + this.request = undefined + this.componentVersion++ + ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight),true) + } + + getCurrentContext(): common.UIAbilityContext { + if (this.currentContext == undefined) { + this.currentContext = getContext(this) as common.UIAbilityContext + } + return this.currentContext + } + + getRequest(width: number, height: number): ImageKnifeRequest { + if (this.request == undefined) { + this.request = new ImageKnifeRequest( + this.imageKnifeOption, + this.imageKnifeOption.context !== undefined ? this.imageKnifeOption.context : this.getCurrentContext(), + width, + height, + this.componentVersion, + { + showPixelMap: async (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource,imageAnimator?: Array) => { + if (version !== this.componentVersion) { + return //针对reuse场景,不显示历史图片 + } + if (imageAnimator != undefined) { + this.imageAnimator = imageAnimator + } else { + this.imageAnimator = [ + { + src: pixelMap + } + ] + } + + if (requestSource == ImageKnifeRequestSource.SRC) { + this.objectFit = + this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit + } else if (requestSource == ImageKnifeRequestSource.PLACE_HOLDER) { + this.objectFit = + this.imageKnifeOption.placeholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.placeholderObjectFit + } else { + this.objectFit = + this.imageKnifeOption.errorholderObjectFit === undefined ? (this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit) : this.imageKnifeOption.errorholderObjectFit + } + } + }) + } + + return this.request + } +} \ No newline at end of file diff --git a/library/src/main/ets/key/DefaultEngineKey.ets b/library/src/main/ets/key/DefaultEngineKey.ets index b2d3600..cd83bc8 100644 --- a/library/src/main/ets/key/DefaultEngineKey.ets +++ b/library/src/main/ets/key/DefaultEngineKey.ets @@ -22,8 +22,8 @@ import { ImageKnifeRequestSource } from '../model/ImageKnifeData'; export class DefaultEngineKey implements IEngineKey { // 生成内存缓存key generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, - imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string { - let key = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + imageKnifeOption: ImageKnifeOption,isAnimator?:boolean, width?: number, height?: number): string { + let key = (isAnimator == undefined ? "loadSrc=" : "Animator==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" if (requestSource === ImageKnifeRequestSource.SRC) { if (imageKnifeOption.signature !== undefined && imageKnifeOption.signature !== "") { key += "signature=" + imageKnifeOption.signature + ";" @@ -36,8 +36,8 @@ export class DefaultEngineKey implements IEngineKey { } // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string { - let src = "loadSrc=" + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string,isAnimator?:boolean): string { + let src = (isAnimator == undefined ? "loadSrc=" : "Animator==") + (typeof loadSrc == "string" ? loadSrc : JSON.stringify(loadSrc)) + ";" if (signature !== undefined && signature !== "") { src += "signature=" + signature + ";" } diff --git a/library/src/main/ets/key/IEngineKey.ets b/library/src/main/ets/key/IEngineKey.ets index 746df1b..03ade23 100644 --- a/library/src/main/ets/key/IEngineKey.ets +++ b/library/src/main/ets/key/IEngineKey.ets @@ -18,10 +18,10 @@ import { ImageKnifeRequestSource } from '../model/ImageKnifeData' export interface IEngineKey { // 生成内存缓存key generateMemoryKey(loadSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource, - imageKnifeOption: ImageKnifeOption, width?: number, height?: number): string + imageKnifeOption: ImageKnifeOption,isAnimator?:boolean, width?: number, height?: number): string // 生成文件缓存key - generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string): string + generateFileKey(loadSrc: string | PixelMap | Resource, signature?: string,isAnimator?:boolean): string } diff --git a/library/src/main/ets/model/ImageKnifeData.ets b/library/src/main/ets/model/ImageKnifeData.ets index 24104f3..e7af85f 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, + imageAnimator?: Array } /** @@ -60,7 +61,9 @@ export interface RequestJobResult { bufferSize: number fileKey: string loadFail?: string, - size?:Size + size?:Size, + pixelMapList?:Array, + delayList?: Array } /** @@ -82,5 +85,6 @@ export interface RequestJobRequest { engineKey: IEngineKey isWatchProgress: boolean memoryKey: string + isAnimator?: boolean } diff --git a/sharedlibrary/Index.ets b/sharedlibrary/Index.ets index 468219f..8a8eb99 100644 --- a/sharedlibrary/Index.ets +++ b/sharedlibrary/Index.ets @@ -6,10 +6,14 @@ export { IndexComponent } from "./src/main/ets/pages/Index" export { ImageKnifeComponent } from '@ohos/imageknife' +export { ImageKnifeAnimatorComponent } from '@ohos/imageknife' + export { ImageKnife } from '@ohos/imageknife' export { ImageKnifeOption } from '@ohos/imageknife' +export { AnimatorOption } from '@ohos/imageknife' + export { ImageKnifeRequest } from '@ohos/imageknife' export { FileUtils } from '@ohos/imageknife'