From 797eb69c5b2a3f722bcdc9b0a002f538154ab282 Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Thu, 30 Nov 2023 16:37:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9EList=E6=BB=91=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E6=9A=82=E5=81=9C=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD,=20=E6=BB=91=E5=8A=A8=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E4=BA=86=E6=81=A2=E5=A4=8D=E5=9B=BE=E7=89=87=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?demo=202.=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98:=E5=9C=A8pausedRe?= =?UTF-8?q?quests=E4=B8=8D=E4=B8=BB=E5=8A=A8=E5=8E=BB=E5=88=A0=E9=99=A4pau?= =?UTF-8?q?sedMaps=E6=95=B0=E6=8D=AE,=E5=9B=A0=E4=B8=BA=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=9A=82=E5=81=9C=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E6=95=B0=E6=8D=AE=E8=A2=AB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- .../ets/pages/imageknifeTestCaseIndex.ets | 33 ++++++ .../ets/pages/photosPausedResumedPage2.ets | 104 ++++++++++++++++++ .../resources/base/profile/main_pages.json | 1 + .../ets/components/imageknife/ImageKnife.ets | 1 - 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 entry/src/main/ets/pages/photosPausedResumedPage2.ets diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index dc48f66..161fcf8 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -233,6 +233,39 @@ struct IndexFunctionDemo { }.width('100%').height(60).backgroundColor(Color.Pink) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + + Button("大量照片和重复数据") + .onClick(() => { + console.log("pages/manyPhotoShowPage 页面跳转") + router.pushUrl({ url: "pages/manyPhotoShowPage" }); + }).margin({ top: 15 }) + Button("部分url测试") + .onClick(() => { + console.log("pages/tempUrlTestPage 页面跳转") + router.pushUrl({ url: "pages/tempUrlTestPage" }); + }).margin({ top: 15 }) + Button("测试drawFactory") + .onClick(() => { + console.log("pages/drawFactoryTestPage 页面跳转") + router.pushUrl({ url: "pages/drawFactoryTestPage" }); + }).margin({ top: 15 }) + + }.width('100%').height(60).backgroundColor(Color.Pink) + + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Button("图片加载暂停和恢复") + .onClick(() => { + console.log("pages/photosPausedResumedPage 页面跳转") + router.pushUrl({ url: "pages/photosPausedResumedPage" }); + }).margin({ top: 15 }) + Button("List滑动时暂停图片加载,滑动结束恢复图片加载") + .onClick(() => { + console.log("pages/photosPausedResumedPage2 页面跳转") + router.pushUrl({ url: "pages/photosPausedResumedPage2" }); + }).margin({ top: 15 }) + }.width('100%').height(60).backgroundColor(Color.Pink) + Text("单帧gif测试").fontSize(15) Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Button("单帧gif测试") diff --git a/entry/src/main/ets/pages/photosPausedResumedPage2.ets b/entry/src/main/ets/pages/photosPausedResumedPage2.ets new file mode 100644 index 0000000..6b043df --- /dev/null +++ b/entry/src/main/ets/pages/photosPausedResumedPage2.ets @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2021 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, ScaleType,ImageKnife} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {Material} from './model/Material' +import {TestDataSource} from './model/TestDataSource' +import {DiskLruCache} from '@ohos/disklrucache' +import ArkWorker from '@ohos.worker' +import Prompt from '@system.prompt' +@Entry +@Component +struct photosPausedResumedPage { + private data: TestDataSource = new TestDataSource(); + + private elementScroller: Scroller = new Scroller() + + build() { + Column() { + + Button('这个List通过监听: 开始滑动,停止加载图片;滑动结束,恢复加载图片') + .margin({top:10,bottom:5}) + .onClick(()=>{ + + }) + + + + + List({ space: 20, scroller: this.elementScroller }) { + LazyForEach(this.data, (item: Material, index) => { + ListItem() { + Column() { + Stack({ alignContent: Alignment.BottomEnd }) { + // 滤镜图片 + ImageKnifeComponent({ imageKnifeOption: { + loadSrc: item.thumbnail, + mainScaleType: ScaleType.FIT_XY, + } }) + } + .width(56).height(56) + //滤镜标题 + Text(item.name) + .fontSize(10) + .maxLines(1) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .layoutWeight(1) + .width('100%') + .backgroundColor(Color.Orange) + } + .width(56) + .height(72) + .clip(true) + .borderRadius(4) + } + }, (item: Material) => item.material_id) + } + .onScrollStart(()=>{ + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife!= undefined){ + imageKnife.pauseRequests() + } + }) + .onScrollStop(()=>{ + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife!= undefined){ + imageKnife.resumeRequests() + } + }) + .listDirection(Axis.Horizontal) + .width('100%') + .height(72) + + } + } + + + aboutToDisappear(){ + // 如果用户滑动过程中就退出了页面我们需要恢复图片加载能力 + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife!= undefined){ + imageKnife.resumeRequests() + } + } + + + +} + + diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index eadd98b..be0efeb 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -25,6 +25,7 @@ "pages/dataShareUriLoadPage", "pages/manyPhotoShowPage", "pages/photosPausedResumedPage", + "pages/photosPausedResumedPage2", "pages/tempUrlTestPage", "pages/drawFactoryTestPage", "pages/testSingleFrameGifPage", diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets index 57c7e3b..95463a5 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets @@ -217,7 +217,6 @@ export class ImageKnife { this.isPaused = true; // 将未删除的所有request [run pend] 放入 [pause] - this.pausedMaps.clear() LogUtil.log('dodo pauseRequests start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) // 将run存入pause