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