!70 修复多次暂停导致无法加载图片的问题

Merge pull request !70 from zhoulisheng2/master
This commit is contained in:
openharmony_ci 2023-11-30 09:36:48 +00:00 committed by Gitee
commit db7f176084
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 138 additions and 1 deletions

View File

@ -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测试")

View File

@ -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()
}
}
}

View File

@ -25,6 +25,7 @@
"pages/dataShareUriLoadPage",
"pages/manyPhotoShowPage",
"pages/photosPausedResumedPage",
"pages/photosPausedResumedPage2",
"pages/tempUrlTestPage",
"pages/drawFactoryTestPage",
"pages/testSingleFrameGifPage",

View File

@ -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