From 7f51e9164e66cde55ede5c23d851349a4a4d2481 Mon Sep 17 00:00:00 2001 From: tyBrave Date: Mon, 21 Oct 2024 14:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EonLoadCancel=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=9B=9E=E8=B0=83=E7=9A=84demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tyBrave --- .../ets/pages/TestLoadCancelListenerPage.ets | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 entry/src/main/ets/pages/TestLoadCancelListenerPage.ets diff --git a/entry/src/main/ets/pages/TestLoadCancelListenerPage.ets b/entry/src/main/ets/pages/TestLoadCancelListenerPage.ets new file mode 100644 index 0000000..2d9f75a --- /dev/null +++ b/entry/src/main/ets/pages/TestLoadCancelListenerPage.ets @@ -0,0 +1,95 @@ +/* + * 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 { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; + + +@Entry +@Component +struct TestLoadCancelListenerPage { + @State currentWidth: number = 200 + @State currentHeight: number = 200 + @State showChild: boolean = true; + @State text: string = ""; + @State ImageKnifeOption: ImageKnifeOption = { + loadSrc: "", + objectFit: ImageFit.Contain, + border: { radius: 50 } + }; + + build() { + Column() { + Text($r('app.string.onLoadCancel_reason', this.text)).margin(20).fontSize(15) + Button($r('app.string.rm_component_of_net')) + .margin(20) + .onClick(() => { + this.ImageKnifeOption = { + loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg", + objectFit: ImageFit.Contain, + onLoadListener: { + onLoadStart: () => { + this.showChild = false; + }, + onLoadCancel: (res) => { + this.text = res + console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res) + } + }, + border: { radius: 50 } + } + }) + + Button($r('app.string.component_display')) + .margin(20).onClick(() => { + this.text = ""; + this.showChild = true; + this.ImageKnifeOption = { + loadSrc: "", + objectFit: ImageFit.Contain, + border: { radius: 50 } + } + }) + Button($r('app.string.rm_component_of_local')) + .margin(20) + .onClick(() => { + this.ImageKnifeOption = { + loadSrc: $r('app.media.loading'), + objectFit: ImageFit.Contain, + onLoadListener: { + onLoadStart: () => { + this.showChild = false; + }, + onLoadCancel: (res) => { + this.text = res + console.log("TestLoadCancelListenerPage----onLoadCancel> url:" + res) + } + }, + border: { radius: 50 } + } + }) + + if (this.showChild) { + ImageKnifeComponent( + { imageKnifeOption: this.ImageKnifeOption }) + .height(150) + .width(150) + .backgroundColor(Color.Orange) + .margin({ top: 20 }) + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file