Pre Merge pull request !297 from zgf/master

This commit is contained in:
zgf 2024-06-11 08:20:16 +00:00 committed by Gitee
commit 553a44230a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 15 additions and 7 deletions

View File

@ -5,6 +5,7 @@
- 支持多种组合变换 - 支持多种组合变换
- 提供清理缓存能力 - 提供清理缓存能力
- 修复preLoad接口失效 - 修复preLoad接口失效
- 修复复用场景下从内存获取图片后又清空了画布导致图片不显示
## 2.2.0-rc.2 ## 2.2.0-rc.2
- ImageKnife支持下采样 - ImageKnife支持下采样

View File

@ -744,7 +744,7 @@ export class ImageKnife {
if (requestOption.requestState === ImageKnifeRequestState.PROGRESS) { if (requestOption.requestState === ImageKnifeRequestState.PROGRESS) {
requestOption.requestState = ImageKnifeRequestState.COMPLETE; requestOption.requestState = ImageKnifeRequestState.COMPLETE;
} }
requestOption.loadComplete(mainCache as ImageKnifeData); requestOption.loadComplete(mainCache as ImageKnifeData,true);
}) })
} }
return; return;

View File

@ -36,6 +36,7 @@ interface KeyCanvas {
@Component @Component
export struct ImageKnifeComponent { export struct ImageKnifeComponent {
@Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption; @Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption;
isClearRect: boolean = true
private settings: RenderingContextSettings = new RenderingContextSettings(true) private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private hasDisplayRetryholder = false; private hasDisplayRetryholder = false;
@ -171,6 +172,7 @@ export struct ImageKnifeComponent {
} }
this.request = new RequestOption(); this.request = new RequestOption();
this.lastSrc = this.imageKnifeOption.loadSrc; this.lastSrc = this.imageKnifeOption.loadSrc;
this.isClearRect = true
this.whetherWaitSize(); this.whetherWaitSize();
} }
} }
@ -215,7 +217,7 @@ export struct ImageKnifeComponent {
configNecessary(request: RequestOption) { configNecessary(request: RequestOption) {
request.load(this.imageKnifeOption.loadSrc) request.load(this.imageKnifeOption.loadSrc)
.addListener({ callback: (err:BusinessError|string, data:ImageKnifeData) => { .addListener({ callback: (err:BusinessError|string, data:ImageKnifeData,isMainCache?:boolean) => {
LogUtil.log('VISIBLE: ImageKnifeComponent request.load callback, err: ' + err); LogUtil.log('VISIBLE: ImageKnifeComponent request.load callback, err: ' + err);
if (err != "" && this.imageKnifeOption.onLoadListener && this.imageKnifeOption.onLoadListener.onLoadFailed) { if (err != "" && this.imageKnifeOption.onLoadListener && this.imageKnifeOption.onLoadListener.onLoadFailed) {
this.imageKnifeOption.onLoadListener.onLoadFailed(err as string); this.imageKnifeOption.onLoadListener.onLoadFailed(err as string);
@ -239,6 +241,10 @@ export struct ImageKnifeComponent {
} else { } else {
this.isGif = false this.isGif = false
} }
if(isMainCache) {
this.context.clearRect(0,0,this.context.width,this.context.height)
this.isClearRect = false
}
if(this.lastSrc !== request.loadSrc && this.lastSrc !== ""){} if(this.lastSrc !== request.loadSrc && this.lastSrc !== ""){}
else { else {
// 组件 没有被销毁 执行渲染逻辑 // 组件 没有被销毁 执行渲染逻辑
@ -780,9 +786,10 @@ export struct ImageKnifeComponent {
} }
aboutToReuse(params: ESObject) { aboutToReuse(params: ESObject) {
LogUtil.log('VISIBLE: Reuse happened!'); LogUtil.log('VISIBLE: Reuse happened!');
this.context.clearRect(0,0,this.context.width,this.context.height) if(this.isClearRect) {
this.context.clearRect(0,0,this.context.width,this.context.height)
}
// watch方法会触发两次,第二次触发不会执行加载逻辑,reuse比watch晚,因此需要手动在此处触发加载逻辑 // watch方法会触发两次,第二次触发不会执行加载逻辑,reuse比watch晚,因此需要手动在此处触发加载逻辑
this.whetherWaitSize();
} }
aboutToAppear() { aboutToAppear() {
LogUtil.log('VISIBLE: ImageKnifeComponent aboutToAppear happened!') LogUtil.log('VISIBLE: ImageKnifeComponent aboutToAppear happened!')

View File

@ -591,13 +591,13 @@ export class RequestOption {
fallbackOnError = (error: BusinessError | string) => { fallbackOnError = (error: BusinessError | string) => {
LogUtil.error("失败占位图解析失败 error =" + JSON.stringify(error)); LogUtil.error("失败占位图解析失败 error =" + JSON.stringify(error));
} }
loadComplete = (imageKnifeData: ImageKnifeData) => { loadComplete = (imageKnifeData: ImageKnifeData,isMainCache?:boolean) => {
this.loadMainReady = true; this.loadMainReady = true;
// 三级缓存数据加载成功 // 三级缓存数据加载成功
if (this.requestListeners != undefined) { if (this.requestListeners != undefined) {
for (let i = 0; i < this.requestListeners.length; i++) { for (let i = 0; i < this.requestListeners.length; i++) {
let requestListener = this.requestListeners[i]; let requestListener = this.requestListeners[i];
let boolInterception = requestListener.callback("", imageKnifeData); let boolInterception = requestListener.callback("", imageKnifeData,isMainCache);
if (boolInterception) { if (boolInterception) {
break; break;
} }

View File

@ -14,5 +14,5 @@
*/ */
export interface AsyncCallback<T> { export interface AsyncCallback<T> {
callback:(err: string, data: T)=>boolean; callback:(err: string, data: T,isMainCache?:boolean)=>boolean;
} }