新增preload预加载和cancel取消加载接口,添加prefetch配合preload接口样例
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
aa2cd9c1bf
commit
4383fa3659
|
@ -1,3 +1,8 @@
|
||||||
|
## 3.0.2
|
||||||
|
- 新增图片重新加载接口reload
|
||||||
|
- 新增返回请求request预加载接口preload
|
||||||
|
- 新增取消请求接口cancel
|
||||||
|
|
||||||
## 3.0.2-rc.2
|
## 3.0.2-rc.2
|
||||||
- ImageKnifeAnimatorComponent新增开始、结束、暂停的回调事件
|
- ImageKnifeAnimatorComponent新增开始、结束、暂停的回调事件
|
||||||
- 文件缓存数量负数和超过INT最大值时默认为INT最大值
|
- 文件缓存数量负数和超过INT最大值时默认为INT最大值
|
||||||
|
|
|
@ -316,6 +316,8 @@ ImageKnifeAnimatorComponent({
|
||||||
| initMemoryCache | newMemoryCache: IMemoryCache | 自定义内存缓存策略 |
|
| initMemoryCache | newMemoryCache: IMemoryCache | 自定义内存缓存策略 |
|
||||||
| initFileCache | context: Context, size: number, memory: number | 初始化文件缓存数量和大小 |
|
| initFileCache | context: Context, size: number, memory: number | 初始化文件缓存数量和大小 |
|
||||||
| reload | request: ImageKnifeRequest | 图片重新加载 |
|
| reload | request: ImageKnifeRequest | 图片重新加载 |
|
||||||
|
| preLoad | loadSrc: string I ImageKnifeOption | 预加载返回图片请求request |
|
||||||
|
| cancel | request: ImageKnifeRequest | 取消图片请求 |
|
||||||
| preLoadCache | loadSrc: string I ImageKnifeOption | 预加载并返回文件缓存路径 |
|
| preLoadCache | loadSrc: string I ImageKnifeOption | 预加载并返回文件缓存路径 |
|
||||||
| getCacheImage | loadSrc: string, cacheType: CacheStrategy = CacheStrategy.Default, signature?: string) | 从内存或文件缓存中获取资源 |
|
| getCacheImage | loadSrc: string, cacheType: CacheStrategy = CacheStrategy.Default, signature?: string) | 从内存或文件缓存中获取资源 |
|
||||||
| addHeader | key: string, value: Object | 全局添加http请求头 |
|
| addHeader | key: string, value: Object | 全局添加http请求头 |
|
||||||
|
|
|
@ -40,6 +40,11 @@ struct Index {
|
||||||
uri: 'pages/ImageKnifeReload',
|
uri: 'pages/ImageKnifeReload',
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Button("动态预加载prefetch").margin({top:10}).onClick(()=>{
|
||||||
|
router.push({
|
||||||
|
uri: 'pages/PrefetchAndCacheCount',
|
||||||
|
});
|
||||||
|
})
|
||||||
Button($r('app.string.Test_multiple_images')).margin({top:10}).onClick(()=>{
|
Button($r('app.string.Test_multiple_images')).margin({top:10}).onClick(()=>{
|
||||||
router.push({
|
router.push({
|
||||||
uri: 'pages/TestCommonImage',
|
uri: 'pages/TestCommonImage',
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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 { InfoItem } from './model/DataSourcePrefetching';
|
||||||
|
import { PageViewModel } from './model/PageViewModel';
|
||||||
|
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||||
|
import { CommonDataSource } from './model/CommonDataSource';
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
export struct LazyForEachCache {
|
||||||
|
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
|
||||||
|
aboutToAppear(): void {
|
||||||
|
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
|
||||||
|
}
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
List({ space: 16 }) {
|
||||||
|
LazyForEach(this.hotCommendList, (item: InfoItem,index) => {
|
||||||
|
ListItem() {
|
||||||
|
Column({ space: 12 }) {
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc: item.albumUrl,
|
||||||
|
placeholderSrc:$r('app.media.loading')
|
||||||
|
}
|
||||||
|
}).width(100).height(100)
|
||||||
|
Text(`${index}`)
|
||||||
|
}.border({ width: 5 , color: "#000000"})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.cachedCount(5)
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
.margin({ left: 10, right: 10 })
|
||||||
|
.layoutWeight(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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 { InfoItem } from './model/DataSourcePrefetching';
|
||||||
|
import { PageViewModel } from './model/PageViewModel';
|
||||||
|
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||||
|
import { CommonDataSource } from './model/CommonDataSource';
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
export struct LazyForEachCount {
|
||||||
|
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
|
||||||
|
aboutToAppear(): void {
|
||||||
|
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
|
||||||
|
}
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
List({ space: 16 }) {
|
||||||
|
LazyForEach(this.hotCommendList, (item: InfoItem,index) => {
|
||||||
|
ListItem() {
|
||||||
|
Column({ space: 12 }) {
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc: item.albumUrl,
|
||||||
|
placeholderSrc:$r('app.media.loading')
|
||||||
|
}
|
||||||
|
}).width(100).height(100)
|
||||||
|
Text(`${index}`)
|
||||||
|
}.border({ width: 5 , color: "#000000"})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.cachedCount(30)
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
.margin({ left: 10, right: 10 })
|
||||||
|
.layoutWeight(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 { router } from '@kit.ArkUI'
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct PrefetchAndCacheCount {
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
Button("cacheCount == 5")
|
||||||
|
.onClick(()=>{
|
||||||
|
router.pushUrl({url:"pages/LazyForEachCache"})
|
||||||
|
})
|
||||||
|
Button("cacheCount == 30")
|
||||||
|
.margin({top:10})
|
||||||
|
.onClick(()=>{
|
||||||
|
router.pushUrl({url:"pages/LazyForEachCount"})
|
||||||
|
})
|
||||||
|
Button("prefetch + preload")
|
||||||
|
.margin({top:10})
|
||||||
|
.onClick(()=>{
|
||||||
|
router.pushUrl({url:"pages/PrefetchAndPreload"})
|
||||||
|
})
|
||||||
|
}.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* 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 { BasicPrefetcher } from '@kit.ArkUI';
|
||||||
|
import DataSourcePrefetchingImageKnife, { InfoItem } from './model/DataSourcePrefetching';
|
||||||
|
import { PageViewModel } from './model/PageViewModel';
|
||||||
|
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
export struct PrefetchAndPreload {
|
||||||
|
// 创建DataSourcePrefetchingImageKnife对象,具备任务预取、取消能力的数据源
|
||||||
|
private readonly dataSource = new DataSourcePrefetchingImageKnife(PageViewModel.getItems());
|
||||||
|
// 创建BasicPrefetcher对象,默认的动态预取算法实现
|
||||||
|
private readonly prefetcher = new BasicPrefetcher(this.dataSource);
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
List({ space: 16 }) {
|
||||||
|
LazyForEach(this.dataSource, (item: InfoItem,index:number) => {
|
||||||
|
ListItem() {
|
||||||
|
Column({ space: 12 }) {
|
||||||
|
ImageKnifeComponent({
|
||||||
|
imageKnifeOption:{
|
||||||
|
loadSrc: item.albumUrl,
|
||||||
|
placeholderSrc:$r('app.media.loading')
|
||||||
|
}
|
||||||
|
}).width(100).height(100)
|
||||||
|
Text(`${index}`)
|
||||||
|
}.border({ width: 5 , color: "#000000"})
|
||||||
|
}
|
||||||
|
.reuseId('imageKnife')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.cachedCount(5)
|
||||||
|
.onScrollIndex((start: number, end: number) => {
|
||||||
|
// 列表滚动触发visibleAreaChanged,实时更新预取范围,触发调用prefetch、cancel接口
|
||||||
|
this.prefetcher.visibleAreaChanged(start, end)
|
||||||
|
})
|
||||||
|
.width("100%")
|
||||||
|
.height("100%")
|
||||||
|
.margin({ left: 10, right: 10 })
|
||||||
|
.layoutWeight(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,48 +12,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import { CommonDataSource } from './model/CommonDataSource'
|
||||||
import { UserAvatar } from './User'
|
import { UserAvatar } from './User'
|
||||||
|
|
||||||
class CommonDataSource <T> implements IDataSource {
|
|
||||||
private dataArray: T[] = []
|
|
||||||
private listeners: DataChangeListener[] = []
|
|
||||||
|
|
||||||
constructor(element: []) {
|
|
||||||
this.dataArray = element
|
|
||||||
}
|
|
||||||
|
|
||||||
public getData(index: number) {
|
|
||||||
return this.dataArray[index]
|
|
||||||
}
|
|
||||||
|
|
||||||
public totalCount(): number {
|
|
||||||
return this.dataArray.length
|
|
||||||
}
|
|
||||||
|
|
||||||
public addData(index: number, data: T[]): void {
|
|
||||||
this.dataArray = this.dataArray.concat(data)
|
|
||||||
this.notifyDataAdd(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
|
||||||
const pos = this.listeners.indexOf(listener);
|
|
||||||
if (pos >= 0) {
|
|
||||||
this.listeners.splice(pos, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerDataChangeListener(listener: DataChangeListener): void {
|
|
||||||
if (this.listeners.indexOf(listener) < 0) {
|
|
||||||
this.listeners.push(listener)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyDataAdd(index: number): void {
|
|
||||||
this.listeners.forEach((listener: DataChangeListener) => {
|
|
||||||
listener.onDataAdd(index)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
struct Index {
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
export class CommonDataSource <T> implements IDataSource {
|
||||||
|
private dataArray: T[] = []
|
||||||
|
private listeners: DataChangeListener[] = []
|
||||||
|
|
||||||
|
constructor(element: []) {
|
||||||
|
this.dataArray = element
|
||||||
|
}
|
||||||
|
|
||||||
|
public getData(index: number) {
|
||||||
|
return this.dataArray[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
public totalCount(): number {
|
||||||
|
return this.dataArray.length
|
||||||
|
}
|
||||||
|
|
||||||
|
public addData(index: number, data: T[]): void {
|
||||||
|
this.dataArray = this.dataArray.concat(data)
|
||||||
|
this.notifyDataAdd(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||||
|
const pos = this.listeners.indexOf(listener);
|
||||||
|
if (pos >= 0) {
|
||||||
|
this.listeners.splice(pos, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerDataChangeListener(listener: DataChangeListener): void {
|
||||||
|
if (this.listeners.indexOf(listener) < 0) {
|
||||||
|
this.listeners.push(listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyDataAdd(index: number): void {
|
||||||
|
this.listeners.forEach((listener: DataChangeListener) => {
|
||||||
|
listener.onDataAdd(index)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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 {ImageKnife, ImageKnifeRequest} from "@ohos/libraryimageknife"
|
||||||
|
import { IDataSourcePrefetching } from '@kit.ArkUI';
|
||||||
|
import { HashMap } from '@kit.ArkTS';
|
||||||
|
|
||||||
|
const IMADE_UNAVAILABLE = $r('app.media.failed')
|
||||||
|
export interface InfoItem {
|
||||||
|
albumUrl: string | Resource
|
||||||
|
}
|
||||||
|
export default class DataSourcePrefetchingImageKnife implements IDataSourcePrefetching {
|
||||||
|
private dataArray: Array<InfoItem>
|
||||||
|
private readonly requestList: HashMap<number,ImageKnifeRequest> = new HashMap()
|
||||||
|
private listeners: DataChangeListener[] = [];
|
||||||
|
|
||||||
|
constructor(dataArray: Array<InfoItem>) {
|
||||||
|
this.dataArray = dataArray;
|
||||||
|
}
|
||||||
|
public getData(index: number) {
|
||||||
|
return this.dataArray[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
public totalCount(): number {
|
||||||
|
return this.dataArray.length
|
||||||
|
}
|
||||||
|
|
||||||
|
public addData(index: number, data: InfoItem[]): void {
|
||||||
|
this.dataArray = this.dataArray.concat(data)
|
||||||
|
this.notifyDataAdd(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||||
|
const pos = this.listeners.indexOf(listener);
|
||||||
|
if (pos >= 0) {
|
||||||
|
this.listeners.splice(pos, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerDataChangeListener(listener: DataChangeListener): void {
|
||||||
|
if (this.listeners.indexOf(listener) < 0) {
|
||||||
|
this.listeners.push(listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyDataAdd(index: number): void {
|
||||||
|
this.listeners.forEach((listener: DataChangeListener) => {
|
||||||
|
listener.onDataAdd(index)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
async prefetch(index: number): Promise<void> {
|
||||||
|
let item = this.dataArray[index]
|
||||||
|
if (typeof item.albumUrl == "string") {
|
||||||
|
// 图片预加载
|
||||||
|
let request = ImageKnife.getInstance().preload({
|
||||||
|
loadSrc:item.albumUrl,
|
||||||
|
onLoadListener:{
|
||||||
|
onLoadSuccess:()=>{
|
||||||
|
// 预加载成功,删除成功请求
|
||||||
|
this.requestList.remove(index)
|
||||||
|
},
|
||||||
|
onLoadFailed:()=>{
|
||||||
|
// 移除失败请求
|
||||||
|
this.requestList.remove(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.requestList.set(index,request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 取消请求处理
|
||||||
|
cancel(index: number) {
|
||||||
|
if(this.requestList.hasKey(index)) {
|
||||||
|
// 返回MAP对象指定元素
|
||||||
|
const request = this.requestList.get(index)
|
||||||
|
// 取消请求
|
||||||
|
ImageKnife.getInstance().cancel(request)
|
||||||
|
// 移除被取消的请求对象
|
||||||
|
this.requestList.remove(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
* 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 { InfoItem } from './DataSourcePrefetching'
|
||||||
|
|
||||||
|
export class PageViewModel {
|
||||||
|
private static dataArray: Array<InfoItem> = [
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/8a/v3/ZKzYV5BJTuCk5hCE0y_xNA/8JT95OQnSZSd6_xQQUONhQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/1/v3/sTXb_I7URBKjdMyLDYa19w/qpcwa_FNQmi3-EzjbGsJ8A.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e5/v3/m7wFvw_eQIuDV0Mk0IKi8g/gJU4migzTHKYk5KrgdZbBw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3f/v3/k_UWbB5_RGW7JemQZ0OQdw/_DUdmaZRQyG-Oyvkb663Bw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/39/v3/rFRN7G_VSo-p4mBjTZtkRw/gBwTI-ieSIqSsSmLNBEcgw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/04/v3/6K8BPYKVQFOr7KCuAG9nog/qKd3pZlrQy2M-feB3ycVPA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/7d/v3/f0GQFzm1T6eduVeMUhO3Wg/-4cvzIJiRCegjIno3ofIbQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e4/v3/C0xxsSeySxW-2iYR5OEbpQ/f1GlaD3zTeKPX8Vd-M1oVQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/c2/v3/32LCyXN4TuWKWcdf9gAwWw/ej14_BCJQNCaWOKoI9aZAw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fd/v3/LyYJMdMmQNaC5GyBYEZ5Pw/uFLiovypRSagKyIS-UJPVw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/15/v3/MHM9KaWGTgubn6M8-B_6nw/1YO9JyYhTHSBWsoiqYkGZw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/4c/v3/UdYfbv1_QYqn_ulDHp89OA/VkjexMluTqGO3yt3gPK1DA.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e8/v3/N8blT_7qSK-tRtahIyov7g/M_kjGEEmSzOlTc47Zrfozg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/28/v3/VS_h3m4YRrSgbgxnqE3vtQ/h-2Q1Qy2SSGEuXM36-Rq_w.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/2e/v3/R-BaM5ToRNGq5rwtNTcnww/Q2e01VHiR2y9KtFaZmpmNQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/88/v3/3djkAJKKTdC539XqMdstSg/wHO7DxvXQS2xbt2Y_-4BNg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/guw4eiggR3uWjscFTxITYg/TzRB35iPTdCztrZUUaNuFg.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/93/v3/UvSh_f1LT66i0-3hvsYN_A/eYnE3Z8YT5Sk7F-vS2ZmCQ.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/5/v3/tv8Vqf9hQrKpozGeZWg2mw/VEICB-bmQYi0Iv6TGADbhw.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/4v1Ot5BRR6OFVQ9MGn9Xxg/xrPgRn0LS1ep-r7ewIuwiw.jpg"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
static getItems() {
|
||||||
|
return PageViewModel.dataArray
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,10 @@
|
||||||
"pages/TestSetCustomImagePage",
|
"pages/TestSetCustomImagePage",
|
||||||
"pages/TestErrorHolderPage",
|
"pages/TestErrorHolderPage",
|
||||||
"pages/TestTaskResourcePage",
|
"pages/TestTaskResourcePage",
|
||||||
"pages/ImageKnifeReload"
|
"pages/ImageKnifeReload",
|
||||||
|
"pages/LazyForEachCount",
|
||||||
|
"pages/LazyForEachCache",
|
||||||
|
"pages/PrefetchAndCacheCount",
|
||||||
|
"pages/PrefetchAndPreload"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
"main": "index.ets",
|
"main": "index.ets",
|
||||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "3.0.2-rc.2",
|
"version": "3.0.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ohos/gpu_transform": "^1.0.2"
|
"@ohos/gpu_transform": "^1.0.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -145,8 +145,39 @@ export class ImageKnife {
|
||||||
let key = this.getEngineKeyImpl().generateMemoryKey(imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC, imageKnifeOption);
|
let key = this.getEngineKeyImpl().generateMemoryKey(imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC, imageKnifeOption);
|
||||||
this.memoryCache.remove(key);
|
this.memoryCache.remove(key);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 预加载
|
||||||
|
* @param loadSrc 图片地址url
|
||||||
|
* @returns 图片请求request
|
||||||
|
*/
|
||||||
|
preload(loadSrc:string | ImageKnifeOption):ImageKnifeRequest{
|
||||||
|
let imageKnifeOption = new ImageKnifeOption()
|
||||||
|
if (typeof loadSrc == "string") {
|
||||||
|
imageKnifeOption.loadSrc = loadSrc
|
||||||
|
} else {
|
||||||
|
imageKnifeOption = loadSrc;
|
||||||
|
}
|
||||||
|
let request = new ImageKnifeRequest(
|
||||||
|
imageKnifeOption,
|
||||||
|
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext(this) as common.UIAbilityContext,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this.execute(request)
|
||||||
|
return request
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 取消图片请求
|
||||||
|
* @param request 图片请求request
|
||||||
|
*/
|
||||||
|
cancel(request:ImageKnifeRequest) {
|
||||||
|
request.requestState = ImageKnifeRequestState.DESTROY
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 预加载图片到文件缓存
|
* 预加载图片到文件缓存
|
||||||
* @param loadSrc 图片地址url
|
* @param loadSrc 图片地址url
|
||||||
|
|
Loading…
Reference in New Issue