From 21d9ccad6dca10a0e6a5f39e9117265f1a13382c Mon Sep 17 00:00:00 2001 From: zenggaofeng Date: Wed, 27 Mar 2024 15:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=BB=84=E4=BB=B6=E5=AE=BD?= =?UTF-8?q?=E9=AB=98=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8CanvasRenderingCon?= =?UTF-8?q?text2D=E5=AF=B9=E8=B1=A1=E8=8E=B7=E5=8F=96=E5=AE=BD=E9=AB=98?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8D=E6=94=B9=E5=8F=98=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E5=A4=A7=E5=B0=8F=E5=AF=BC=E8=87=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zenggaofeng --- .../imageknife/ImageKnifeComponent.ets | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 5027b36..d8e8a0c 100644 --- a/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/library/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -40,8 +40,6 @@ export struct ImageKnifeComponent { private hasDisplayRetryholder = false; private lastWidth: number = 0 private lastHeight: number = 0 - private currentWidth: number = 0 - private currentHeight: number = 0 // 定时器id private gifTimerId: number = -1 // 完整gif播放时间 @@ -104,7 +102,6 @@ export struct ImageKnifeComponent { private detachFromLayoutPixelMap :DetachFromLayout|undefined = undefined; listener: inspector.ComponentObserver = inspector.createComponentObserver(this.keyCanvas.keyId) - private value: componentUtils.ComponentInfo = componentUtils.getRectangleById(this.keyCanvas.keyId) @State currentSize : Size = { width: 0.01, @@ -140,18 +137,15 @@ export struct ImageKnifeComponent { }) } onLayoutComplete:()=>void = ():void=>{ - this.value = componentUtils.getRectangleById(this.keyCanvas.keyId); - this.currentWidth = px2vp(this.value.size.width) - this.currentHeight = px2vp(this.value.size.height) - if (this.currentWidth <= 0 || this.currentHeight <= 0) { + if (this.context.width <= 0 || this.context.height <= 0) { // 存在宽或者高为0,此次重回无意义,无需进行request请求 } else { // 前提:宽高值均有效,值>0. 条件1:当前宽高与上一次宽高不同 条件2:当前是第一次绘制 - if ((this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) || this.firstDrawFlag) { + if ((this.context.height != this.lastHeight || this.context.width != this.lastWidth) || this.firstDrawFlag) { this.firstDrawFlag = false; - LogUtil.log('ImageKnifeComponent onAreaChange And Next To Execute. Canvas currentWidth =' + this.currentWidth + ' currentHeight=' + this.currentHeight) - this.lastWidth = this.currentWidth - this.lastHeight = this.currentHeight + LogUtil.log('ImageKnifeComponent onAreaChange And Next To Execute. Canvas currentWidth =' + this.context.width + ' currentHeight=' + this.context.height) + this.lastWidth = this.context.width + this.lastHeight = this.context.height this.imageKnifeExecute() } } @@ -168,7 +162,7 @@ export struct ImageKnifeComponent { * @param drawFirst 是否是aboutToAppear第一次绘制 */ whetherWaitSize(drawFirst?: boolean) { - if (this.currentHeight <= 0 || this.currentWidth <= 0) { + if (this.context.height <= 0 || this.context.width <= 0) { // 宽或者高没有高度,需要等待canvas组件初始化完成 if (drawFirst) { this.firstDrawFlag = true; @@ -325,7 +319,7 @@ export struct ImageKnifeComponent { this.resetGifData() if (this.canvasHasReady) { // 如果canvas已经初始化好了,清空原有的canvas内容 - this.context.clearRect(0, 0, this.currentWidth, this.currentHeight) + this.context.clearRect(0, 0, this.context.width, this.context.height) } return } @@ -347,15 +341,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayPlaceholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayPlaceholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if(this.defaultLifeCycle.displayPlaceholder != undefined) { - this.defaultLifeCycle.displayPlaceholder(this.context, data, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayPlaceholder(this.context, data, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) } @@ -370,15 +364,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayProgress', this.context, percent, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayProgress', this.context, percent, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if(this.defaultLifeCycle.displayProgress != undefined) { - this.defaultLifeCycle.displayProgress(this.context, percent, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayProgress(this.context, percent, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) } @@ -393,15 +387,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayThumbSizeMultiplier', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayThumbSizeMultiplier', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if(this.defaultLifeCycle.displayThumbSizeMultiplier != undefined) { - this.defaultLifeCycle.displayThumbSizeMultiplier(this.context, data, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayThumbSizeMultiplier(this.context, data, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) } @@ -414,15 +408,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayMainSource', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayMainSource', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if(this.defaultLifeCycle.displayMainSource != undefined) { - this.defaultLifeCycle.displayMainSource(this.context, data, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayMainSource(this.context, data, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) } @@ -437,15 +431,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayRetryholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayRetryholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if( this.defaultLifeCycle.displayRetryholder != undefined) { - this.defaultLifeCycle.displayRetryholder(this.context, data, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayRetryholder(this.context, data, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) } @@ -459,15 +453,15 @@ export struct ImageKnifeComponent { return } if (!this.drawLifeCycleHasConsumed( 'displayErrorholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },this.imageKnifeOption.drawLifeCycle)) { if (!this.drawLifeCycleHasConsumed( 'displayErrorholder', this.context, data, this.imageKnifeOption, - this.currentWidth, this.currentHeight, (gifTimeId) => { + this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) },(ImageKnifeGlobal.getInstance().getImageKnife())?.getDefaultLifeCycle())) { if(this.defaultLifeCycle.displayErrorholder != undefined) { - this.defaultLifeCycle.displayErrorholder(this.context, data, this.imageKnifeOption, this.currentWidth, this.currentHeight, (gifTimeId) => { + this.defaultLifeCycle.displayErrorholder(this.context, data, this.imageKnifeOption, this.context.width, this.context.height, (gifTimeId) => { this.setGifTimeId(gifTimeId) }) }