forked from floraachy/ImageKnife
!152 新增磁盘预加载返回文件路径接口prefetchToDiskCache
Merge pull request !152 from zgf/master
This commit is contained in:
commit
90dca0464e
|
@ -1,3 +1,6 @@
|
|||
## 2.1.2-rc.12
|
||||
- 新增磁盘预加载返回文件路径接口prefetchToDiskCache
|
||||
|
||||
## 2.1.2-rc.11
|
||||
- 修复设置磁盘容量最大值出现闪退
|
||||
- 修复概率出现jscrash问题
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"name": "entry",
|
||||
"description": "example description",
|
||||
"repository": {},
|
||||
"version": "2.1.2-rc.11",
|
||||
"version": "2.1.2-rc.12",
|
||||
"dependencies": {
|
||||
"@ohos/libraryimageknife": "file:../sharedlibrary",
|
||||
"@ohos/sharedlibrary2": "file:../sharedlibrary2",
|
||||
|
|
|
@ -124,12 +124,6 @@ struct IndexFunctionDemo {
|
|||
console.log("测试一级内存缓存")
|
||||
router.pushUrl({ url: "pages/testReusePhotoPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试所有缓存信息输出")
|
||||
.onClick(() => {
|
||||
console.log("pages/testAllCacheInfoPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/testAllCacheInfoPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
|
||||
}.width('100%')
|
||||
.height(60).backgroundColor(Color.Pink)
|
||||
Text("测试占位图 失败占位图 功能点").fontSize(15)
|
||||
|
@ -148,6 +142,11 @@ struct IndexFunctionDemo {
|
|||
console.log("测试预加载")
|
||||
router.pushUrl({ url: "pages/testPreloadPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
Button("测试磁盘预加载返回string")
|
||||
.onClick(() => {
|
||||
console.log("测试预加载测试磁盘预加载返回string")
|
||||
router.pushUrl({ url: "pages/testDiskPreLoadPage" });
|
||||
}).margin({ top: 5, left: 3 })
|
||||
|
||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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,ImageKnifeGlobal,ImageKnifeOption,ImageKnifeComponent} from '@ohos/libraryimageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct DiskPreLoadPage {
|
||||
|
||||
@State imageKnifeOption2: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.icon'),
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
};
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Button("预加载图片").onClick(()=>{
|
||||
let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife();
|
||||
if(imageKnife != undefined){
|
||||
imageKnife.prefetchToDiskCache("https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658")
|
||||
.then((resolve)=>{
|
||||
console.log("成功回调 : " + resolve)
|
||||
})
|
||||
.catch((reject: ESObject) => {
|
||||
console.log("失败回调 : " + reject)
|
||||
})
|
||||
}
|
||||
})
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("加载GIF")
|
||||
.onClick(() => {
|
||||
this.imageKnifeOption2 = {
|
||||
loadSrc: 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
displayProgress:true,
|
||||
}
|
||||
}).margin({ top: 5, left: 3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300)
|
||||
}.width('100%').backgroundColor(Color.Pink)
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
"pages/showErrorholderTestCasePage",
|
||||
"pages/transformPixelMapPage",
|
||||
"pages/testPreloadPage",
|
||||
"pages/testDiskPreLoadPage",
|
||||
"pages/testImageKnifeOptionChangedPage",
|
||||
"pages/testImageKnifeOptionChangedPage2",
|
||||
"pages/testImageKnifeOptionChangedPage3",
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"main": "index.ets",
|
||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||
"type": "module",
|
||||
"version": "2.1.2-rc.11",
|
||||
"version": "2.1.2-rc.12",
|
||||
"dependencies": {
|
||||
"pako": "^2.1.0",
|
||||
"@ohos/gpu_transform": "^1.0.0"
|
||||
|
|
|
@ -731,7 +731,33 @@ export class ImageKnife {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
prefetchToDiskCache(url: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let key = this.engineKeyImpl.generateOriginalDiskCacheKey(url, undefined);
|
||||
let cachedPath = this.getDiskMemoryCache().getFileToPath(key);
|
||||
if (cachedPath == null || cachedPath == "" || cachedPath == undefined) {
|
||||
let request = new RequestOption();
|
||||
request.load(url)
|
||||
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
let cachedPath = this.getDiskMemoryCache().getFileToPath(key);
|
||||
resolve(cachedPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
this.call(request);
|
||||
} else {
|
||||
resolve(cachedPath);
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载资源子线程包含流程:网络请求资源->下载资源到本地->解码成ixelMap | GIFFrame[]->缓存到内存和磁盘
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
"name": "imageknife",
|
||||
"description": "example description",
|
||||
"repository": {},
|
||||
"version": "2.1.2-rc.11",
|
||||
"version": "2.1.2-rc.12",
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue