Pre Merge pull request !354 from zgf/master
This commit is contained in:
commit
4101d4f2cc
|
@ -1,3 +1,9 @@
|
|||
## 3.0.1
|
||||
- 修复animatorOption属性设置初始化值失效
|
||||
- 修复图片显示时被释放
|
||||
- 网络请求code为206、204时返回arraybuffer
|
||||
- ImageKnifeComponent显示非必要文件缓存初始化
|
||||
|
||||
## 3.0.1-rc.2
|
||||
- 修复自定义下载失败无失败回调
|
||||
- 增加全局配置自定义下载接口
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"main": "index.ets",
|
||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||
"type": "module",
|
||||
"version": "3.0.1-rc.2",
|
||||
"version": "3.0.1",
|
||||
"dependencies": {
|
||||
"@ohos/gpu_transform": "^1.0.2"
|
||||
},
|
||||
|
|
|
@ -171,7 +171,7 @@ export class ImageKnife {
|
|||
0,
|
||||
0,
|
||||
{
|
||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||
showPixelMap(version: number, imageData: ImageKnifeData) {
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -220,7 +220,8 @@ export class ImageKnife {
|
|||
let memoryKey = this.getEngineKeyImpl()
|
||||
.generateMemoryKey(url, ImageKnifeRequestSource.SRC, { loadSrc: url, signature: signature });
|
||||
let fileKey = this.getEngineKeyImpl().generateFileKey(url, signature);
|
||||
let imageKnifeData: ImageKnifeData = { source: pixelMap, imageWidth: 0, imageHeight: 0 };
|
||||
let imageKnifeData: ImageKnifeData = new ImageKnifeData()
|
||||
imageKnifeData.source = pixelMap
|
||||
switch (cacheType) {
|
||||
case CacheStrategy.Default:
|
||||
this.saveMemoryCache(memoryKey, imageKnifeData);
|
||||
|
@ -327,11 +328,9 @@ export class ImageKnife {
|
|||
let base64Help = new util.Base64Helper()
|
||||
|
||||
let base64str = "data:image/" + typeValue + ";base64," + base64Help.encodeToStringSync(new Uint8Array(buffer))
|
||||
onComplete({
|
||||
source: base64str,
|
||||
imageWidth: 0,
|
||||
imageHeight: 0
|
||||
})
|
||||
let imageKnifeData = new ImageKnifeData()
|
||||
imageKnifeData.source = base64str
|
||||
onComplete(imageKnifeData)
|
||||
}
|
||||
|
||||
let imageSource: image.ImageSource = image.createImageSource(buffer);
|
||||
|
@ -341,11 +340,9 @@ export class ImageKnife {
|
|||
|
||||
imageSource.createPixelMap(decodingOptions)
|
||||
.then((pixelmap: PixelMap) => {
|
||||
onComplete({
|
||||
source: pixelmap,
|
||||
imageWidth: 0,
|
||||
imageHeight: 0
|
||||
})
|
||||
let imageKnifeData = new ImageKnifeData()
|
||||
imageKnifeData.source = pixelmap
|
||||
onComplete(imageKnifeData)
|
||||
imageSource.release()
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -55,11 +55,8 @@ export class ImageKnifeDispatcher {
|
|||
LogUtil.log("ImageKnife_DataTime_showFromMemomry.start:" + request.imageKnifeOption.loadSrc)
|
||||
let memoryCache: ImageKnifeData | undefined;
|
||||
if ((typeof (request.imageKnifeOption.loadSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||
memoryCache = {
|
||||
source: request.imageKnifeOption.loadSrc as image.PixelMap,
|
||||
imageWidth: 0,
|
||||
imageHeight: 0,
|
||||
}
|
||||
memoryCache = new ImageKnifeData()
|
||||
memoryCache.source = request.imageKnifeOption.loadSrc as image.PixelMap
|
||||
} else {
|
||||
memoryCache = ImageKnife.getInstance()
|
||||
.loadFromMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, request.imageKnifeOption,isAnimator));
|
||||
|
@ -75,7 +72,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,memoryCache.imageAnimator)
|
||||
request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache, requestSource)
|
||||
LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.end:" + request.imageKnifeOption.loadSrc)
|
||||
|
||||
if (requestSource == ImageKnifeRequestSource.SRC) {
|
||||
|
@ -175,7 +172,7 @@ export class ImageKnifeDispatcher {
|
|||
requestSource: requestSource,
|
||||
isWatchProgress: isWatchProgress,
|
||||
memoryKey: memoryKey,
|
||||
fileCacheFolder: ImageKnife.getInstance().getFileCache().getCacheFolder(),
|
||||
fileCacheFolder: ImageKnife.getInstance().getFileCache()?.getCacheFolder(),
|
||||
isAnimator:isAnimator
|
||||
}
|
||||
|
||||
|
@ -272,12 +269,11 @@ export class ImageKnifeDispatcher {
|
|||
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.end:"+currentRequest.imageKnifeOption.loadSrc)
|
||||
}
|
||||
|
||||
let ImageKnifeData: ImageKnifeData = {
|
||||
source: pixelmap!,
|
||||
imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width,
|
||||
imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height,
|
||||
type:requestJobResult.type
|
||||
};
|
||||
let imageKnifeData: ImageKnifeData = new ImageKnifeData()
|
||||
imageKnifeData.source = pixelmap!
|
||||
imageKnifeData.imageWidth = requestJobResult.size == undefined ? 0 : requestJobResult.size.width
|
||||
imageKnifeData.imageHeight = requestJobResult.size == undefined ? 0 : requestJobResult.size.height
|
||||
imageKnifeData.type = requestJobResult.type
|
||||
if(requestJobResult.pixelMapList != undefined) {
|
||||
let imageAnimator: Array<ImageFrameInfo> = []
|
||||
requestJobResult.pixelMapList.forEach((item,index)=>{
|
||||
|
@ -286,14 +282,15 @@ export class ImageKnifeDispatcher {
|
|||
duration:requestJobResult.delayList![index]
|
||||
})
|
||||
})
|
||||
ImageKnifeData.imageAnimator = imageAnimator
|
||||
imageKnifeData.imageAnimator = imageAnimator
|
||||
}
|
||||
imageKnifeData.detachFromLayoutSave.detach()
|
||||
// 保存内存缓存
|
||||
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,isAnimator),
|
||||
ImageKnifeData);
|
||||
imageKnifeData);
|
||||
LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.end:"+currentRequest.imageKnifeOption.loadSrc)
|
||||
}
|
||||
if (requestList !== undefined) {
|
||||
|
@ -309,7 +306,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.imageAnimator);
|
||||
imageKnifeData, requestWithSource.source);
|
||||
LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.end:"+currentRequest.imageKnifeOption.loadSrc)
|
||||
}
|
||||
|
||||
|
@ -318,7 +315,7 @@ export class ImageKnifeDispatcher {
|
|||
if (requestWithSource.request.imageKnifeOption.onLoadListener &&
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess) {
|
||||
// 回调请求成功
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData);
|
||||
requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(imageKnifeData.source,imageKnifeData);
|
||||
LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc)
|
||||
}
|
||||
} else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) {
|
||||
|
@ -467,7 +464,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
|
|||
});
|
||||
|
||||
await promise.then((data: number) => {
|
||||
if (data == 200) {
|
||||
if (data == 200 || data == 206 || data == 204) {
|
||||
resBuf = combineArrayBuffers(arrayBuffers)
|
||||
} else {
|
||||
loadError = "HttpDownloadClient has error, http code =" + JSON.stringify(data)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
import { ImageKnifeOption } from './ImageKnifeOption';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { ImageKnifeRequestSource } from './model/ImageKnifeData';
|
||||
import { ImageKnifeData, ImageKnifeRequestSource } from './model/ImageKnifeData';
|
||||
|
||||
|
||||
export class ImageKnifeRequest {
|
||||
|
@ -64,5 +64,5 @@ export enum ImageKnifeRequestState {
|
|||
|
||||
|
||||
export interface ImageKnifeRequestCallback {
|
||||
showPixelMap: (version: number, pixelMap: PixelMap | string , requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => void;
|
||||
showPixelMap: (version: number, imageData: ImageKnifeData , requestSource: ImageKnifeRequestSource) => void;
|
||||
}
|
||||
|
|
|
@ -17,17 +17,14 @@ 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';
|
||||
import { DetachFromLayout, ImageKnifeData, ImageKnifeRequestSource } from '../model/ImageKnifeData';
|
||||
|
||||
@Component
|
||||
export struct ImageKnifeAnimatorComponent {
|
||||
@Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption;
|
||||
@Watch('watchAnimatorOption') @State animatorOption: AnimatorOption = new AnimatorOption();
|
||||
@State animatorOption: AnimatorOption = new AnimatorOption();
|
||||
@State pixelMap: PixelMap | string | undefined = undefined
|
||||
@State imageAnimator: Array<ImageFrameInfo> | 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
|
||||
|
@ -38,6 +35,7 @@ export struct ImageKnifeAnimatorComponent {
|
|||
private currentHeight: number = 0
|
||||
private componentVersion: number = 0
|
||||
private currentContext: common.UIAbilityContext | undefined = undefined
|
||||
private detachFromLayout:DetachFromLayout|undefined = undefined;
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
||||
|
@ -48,6 +46,9 @@ export struct ImageKnifeAnimatorComponent {
|
|||
this.request.requestState = ImageKnifeRequestState.DESTROY
|
||||
this.request = undefined
|
||||
}
|
||||
if(this.detachFromLayout != undefined) {
|
||||
this.detachFromLayout.detach()
|
||||
}
|
||||
}
|
||||
|
||||
aboutToRecycle() {
|
||||
|
@ -64,9 +65,9 @@ export struct ImageKnifeAnimatorComponent {
|
|||
.width(this.adaptiveWidth)
|
||||
.height(this.adaptiveHeight)
|
||||
.border(this.imageKnifeOption.border)
|
||||
.state(this.state)
|
||||
.iterations(this.iterations)
|
||||
.reverse(this.reverse)
|
||||
.state(this.animatorOption.state == undefined ? AnimationStatus.Running : this.animatorOption.state)
|
||||
.iterations(this.animatorOption.iterations == undefined ? -1 : this.animatorOption.iterations)
|
||||
.reverse(this.animatorOption.reverse == undefined ? false : this.animatorOption.reverse)
|
||||
.onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => {
|
||||
this.currentWidth = newValue.width as number
|
||||
this.currentHeight = newValue.height as number
|
||||
|
@ -84,18 +85,6 @@ export struct ImageKnifeAnimatorComponent {
|
|||
})
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -121,16 +110,17 @@ export struct ImageKnifeAnimatorComponent {
|
|||
height,
|
||||
this.componentVersion,
|
||||
{
|
||||
showPixelMap: async (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource,imageAnimator?: Array<ImageFrameInfo>) => {
|
||||
showPixelMap: async (version: number, imageData: ImageKnifeData, requestSource: ImageKnifeRequestSource) => {
|
||||
if (version !== this.componentVersion) {
|
||||
return //针对reuse场景,不显示历史图片
|
||||
}
|
||||
if (imageAnimator != undefined) {
|
||||
this.imageAnimator = imageAnimator
|
||||
this.detachFromLayout = imageData.detachFromLayout
|
||||
if (imageData.imageAnimator != undefined) {
|
||||
this.imageAnimator = imageData.imageAnimator
|
||||
} else {
|
||||
this.imageAnimator = [
|
||||
{
|
||||
src: pixelMap
|
||||
src: imageData.source
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import { ImageKnifeRequest, ImageKnifeRequestState } from '../ImageKnifeRequest'
|
|||
import common from '@ohos.app.ability.common';
|
||||
import { ImageKnife } from '../ImageKnife';
|
||||
import { LogUtil } from '../utils/LogUtil';
|
||||
import { ImageKnifeData, ImageKnifeRequestSource } from '../model/ImageKnifeData';
|
||||
import { DetachFromLayout, ImageKnifeData, ImageKnifeRequestSource } from '../model/ImageKnifeData';
|
||||
import { IEngineKey } from '../key/IEngineKey';
|
||||
import { DefaultEngineKey } from '../key/DefaultEngineKey';
|
||||
|
||||
|
@ -36,6 +36,7 @@ export struct ImageKnifeComponent {
|
|||
private currentHeight: number = 0
|
||||
private componentVersion: number = 0
|
||||
private currentContext: common.UIAbilityContext | undefined = undefined
|
||||
private detachFromLayout:DetachFromLayout|undefined = undefined;
|
||||
|
||||
aboutToAppear(): void {
|
||||
//闪动问题失效,注释相应代码后续修复
|
||||
|
@ -65,6 +66,9 @@ export struct ImageKnifeComponent {
|
|||
this.request.requestState = ImageKnifeRequestState.DESTROY
|
||||
this.request = undefined
|
||||
}
|
||||
if(this.detachFromLayout != undefined) {
|
||||
this.detachFromLayout.detach()
|
||||
}
|
||||
}
|
||||
|
||||
aboutToRecycle() {
|
||||
|
@ -127,11 +131,12 @@ export struct ImageKnifeComponent {
|
|||
height,
|
||||
this.componentVersion,
|
||||
{
|
||||
showPixelMap: async (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource) => {
|
||||
showPixelMap: async (version: number, imageData: ImageKnifeData, requestSource: ImageKnifeRequestSource) => {
|
||||
if (version !== this.componentVersion) {
|
||||
return //针对reuse场景,不显示历史图片
|
||||
}
|
||||
this.pixelMap = pixelMap
|
||||
this.detachFromLayout = imageData.detachFromLayout
|
||||
this.pixelMap = imageData.source
|
||||
if (typeof this.pixelMap !== 'string') {
|
||||
if (this.imageKnifeOption.objectFit === ImageFit.Auto) {
|
||||
let info = await this.pixelMap.getImageInfo()
|
||||
|
|
|
@ -18,13 +18,32 @@ import { IEngineKey } from '../key/IEngineKey'
|
|||
import { PixelMapTransformation } from '../transform/PixelMapTransformation'
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { Size } from '@kit.ArkUI'
|
||||
|
||||
export interface ImageKnifeData {
|
||||
source: PixelMap | string,
|
||||
imageWidth: number,
|
||||
imageHeight: number,
|
||||
type?:string,
|
||||
export interface DetachFromLayout {
|
||||
detach: () => void
|
||||
}
|
||||
export class ImageKnifeData {
|
||||
source: PixelMap | string = ""
|
||||
imageWidth: number = 0
|
||||
imageHeight: number = 0
|
||||
type?:string
|
||||
imageAnimator?: Array<ImageFrameInfo>
|
||||
private isShowOnComponent: boolean = false
|
||||
detachFromLayout: DetachFromLayout = {
|
||||
detach: () => {
|
||||
this.isShowOnComponent = false
|
||||
}
|
||||
}
|
||||
detachFromLayoutSave: DetachFromLayout = {
|
||||
detach: () => {
|
||||
this.isShowOnComponent = true
|
||||
}
|
||||
}
|
||||
|
||||
release(){
|
||||
if(typeof this.source != "string" && this.isShowOnComponent == false) {
|
||||
this.source.release()
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* onComplete成功回调
|
||||
|
|
|
@ -113,7 +113,7 @@ export class MemoryLruCache implements IMemoryCache {
|
|||
}
|
||||
} else {
|
||||
this.currentMemory -= value.source.getPixelBytesNumber();
|
||||
value.source.release()
|
||||
value.release()
|
||||
}
|
||||
// LogUtil.info("MemoryCache removeMemorySize: " + value.source.getPixelBytesNumber() + " currentMemory:" + this.currentMemory)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue