Compare commits
No commits in common. "55fcfe6021fac0fe50502e8f2522e9ad17007dd3" and "b3114dd47b590c18c060e6621c48328da4001b93" have entirely different histories.
55fcfe6021
...
b3114dd47b
|
@ -67,7 +67,6 @@ export class ImageKnifeDispatcher {
|
||||||
|
|
||||||
|
|
||||||
if (memoryCache !== undefined) {
|
if (memoryCache !== undefined) {
|
||||||
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_true:" + request.imageKnifeOption.loadSrc)
|
|
||||||
// 画主图
|
// 画主图
|
||||||
if (request.requestState === ImageKnifeRequestState.PROGRESS) {
|
if (request.requestState === ImageKnifeRequestState.PROGRESS) {
|
||||||
// 回调请求开始
|
// 回调请求开始
|
||||||
|
@ -90,6 +89,7 @@ export class ImageKnifeDispatcher {
|
||||||
request.requestState = ImageKnifeRequestState.ERROR
|
request.requestState = ImageKnifeRequestState.ERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_true:" + request.imageKnifeOption.loadSrc)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_false:" + request.imageKnifeOption.loadSrc)
|
LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_false:" + request.imageKnifeOption.loadSrc)
|
||||||
|
|
|
@ -36,64 +36,54 @@ export struct ImageKnifeComponent {
|
||||||
private componentVersion: number = 0
|
private componentVersion: number = 0
|
||||||
private currentContext: common.UIAbilityContext | undefined = undefined
|
private currentContext: common.UIAbilityContext | undefined = undefined
|
||||||
@Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption();
|
@Param imageKnifeOption: ImageKnifeOption = new ImageKnifeOption();
|
||||||
|
|
||||||
@Monitor('imageKnifeOption',
|
@Monitor('imageKnifeOption',
|
||||||
"imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit")
|
"imageKnifeOption.loadSrc","imageKnifeOption.signature","imageKnifeOption.transformation","imageKnifeOption.border","imageKnifeOption.objectFit")
|
||||||
watchImageKnifeOption() {
|
watchImageKnifeOption() {
|
||||||
this.clearLastRequest()
|
if (this.request !== undefined) {
|
||||||
|
this.request.requestState = ImageKnifeRequestState.DESTROY
|
||||||
|
}
|
||||||
|
this.request = undefined
|
||||||
this.componentVersion++
|
this.componentVersion++
|
||||||
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
|
||||||
LogUtil.log("watchImageKnifeOption execute request:width=" + this.currentWidth + " height= " + this.currentHeight
|
|
||||||
+ " loadSrc = " + this.request?.imageKnifeOption.loadSrc
|
|
||||||
+ " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
|
|
||||||
+ " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
|
|
||||||
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
|
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToAppear(): void {
|
aboutToAppear(): void {
|
||||||
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
//闪动问题失效,注释相应代码后续修复
|
||||||
|
if(this.syncLoad) {
|
||||||
if(this.syncLoad) { //针对部分消息列表最新消息的图片闪动问题,建议使用同步方式在aboutToAppear时加载图片
|
|
||||||
let engineKey: IEngineKey = new DefaultEngineKey();
|
let engineKey: IEngineKey = new DefaultEngineKey();
|
||||||
let memoryCacheSrc: ImageKnifeData | undefined = ImageKnife.getInstance()
|
let memoryCacheSrc: ImageKnifeData | undefined = ImageKnife.getInstance()
|
||||||
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,this.imageKnifeOption))
|
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,this.imageKnifeOption))
|
||||||
if (memoryCacheSrc !== undefined){
|
if (memoryCacheSrc !== undefined){
|
||||||
LogUtil.log("aboutToAppear success load loadSrc from memory cache for loadSrc = "+ this.imageKnifeOption.loadSrc)
|
LogUtil.log("aboutToAppear load from memory cache for key = "+ engineKey.generateMemoryKey(this.imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,this.imageKnifeOption))
|
||||||
|
//画主图
|
||||||
this.pixelMap = memoryCacheSrc.source;
|
this.pixelMap = memoryCacheSrc.source;
|
||||||
}else{
|
}else {
|
||||||
LogUtil.log("aboutToAppear fail load loadSrc from memory cache for loadSrc = "+ this.imageKnifeOption.loadSrc)
|
|
||||||
if (this.imageKnifeOption.placeholderSrc !== undefined){
|
|
||||||
let memoryCachePlace: ImageKnifeData | undefined = ImageKnife.getInstance()
|
let memoryCachePlace: ImageKnifeData | undefined = ImageKnife.getInstance()
|
||||||
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.placeholderSrc!,ImageKnifeRequestSource.PLACE_HOLDER,this.imageKnifeOption))
|
.loadFromMemoryCache(engineKey.generateMemoryKey(this.imageKnifeOption.placeholderSrc!,ImageKnifeRequestSource.PLACE_HOLDER,this.imageKnifeOption))
|
||||||
if (memoryCachePlace !== undefined){
|
if (memoryCachePlace !== undefined){
|
||||||
LogUtil.log("aboutToAppear success load placeholderSrc from memory cache for placeholderSrc = " + this.imageKnifeOption.placeholderSrc)
|
LogUtil.log("aboutToAppear load from memory cache for key = "+ engineKey.generateMemoryKey(this.imageKnifeOption.loadSrc,ImageKnifeRequestSource.SRC,this.imageKnifeOption))
|
||||||
|
//画主图
|
||||||
this.pixelMap = memoryCachePlace.source;
|
this.pixelMap = memoryCachePlace.source;
|
||||||
}else{
|
|
||||||
LogUtil.log("aboutToAppear fail load placeholderSrc from memory cache for placeholderSrc = " + this.imageKnifeOption.placeholderSrc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToDisappear(): void {
|
aboutToDisappear(): void {
|
||||||
this.clearLastRequest()
|
|
||||||
}
|
|
||||||
|
|
||||||
aboutToRecycle() {
|
|
||||||
this.clearLastRequest()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对已DESTROY的组件不再发起请求
|
|
||||||
*/
|
|
||||||
private clearLastRequest(){
|
|
||||||
if (this.request !== undefined) {
|
if (this.request !== undefined) {
|
||||||
this.request.requestState = ImageKnifeRequestState.DESTROY
|
this.request.requestState = ImageKnifeRequestState.DESTROY
|
||||||
this.request = undefined
|
this.request = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aboutToRecycle() {
|
||||||
|
if (this.request !== undefined) {
|
||||||
|
this.request.requestState = ImageKnifeRequestState.DESTROY
|
||||||
|
this.request = undefined
|
||||||
|
}
|
||||||
|
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Image(this.pixelMap)
|
Image(this.pixelMap)
|
||||||
.colorFilter(this.imageKnifeOption.drawingColorFilter)
|
.colorFilter(this.imageKnifeOption.drawingColorFilter)
|
||||||
|
@ -109,16 +99,15 @@ export struct ImageKnifeComponent {
|
||||||
this.currentHeight = newValue.height as number
|
this.currentHeight = newValue.height as number
|
||||||
this.lastWidth = oldValue.width as number
|
this.lastWidth = oldValue.width as number
|
||||||
this.lastHeight = oldValue.height as number
|
this.lastHeight = oldValue.height as number
|
||||||
|
if (this.currentWidth <= 0 || this.currentHeight <= 0) {
|
||||||
// 条件1: 宽高值均有效,值>0. 条件2:当前宽高与上一次宽高不同
|
// 存在宽或者高为0,此次重回无意义,无需进行request请求
|
||||||
if (this.currentWidth > 0 && this.currentHeight > 0 &&
|
} else {
|
||||||
(this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth)) {
|
// 前提:宽高值均有效,值>0. 条件1:当前宽高与上一次宽高不同 条件2:当前是第一次绘制
|
||||||
LogUtil.log("onSizeChange execute request:width=" + this.currentWidth + " height= " + this.currentHeight
|
if (this.currentHeight != this.lastHeight || this.currentWidth != this.lastWidth) {
|
||||||
+ " loadSrc = " + this.request?.imageKnifeOption.loadSrc
|
LogUtil.log("execute request:width=" + this.currentWidth + " height= " + this.currentHeight)
|
||||||
+ " placeholderSrc = " + this.request?.imageKnifeOption.placeholderSrc
|
|
||||||
+ " errorholderSrc = " + this.request?.imageKnifeOption.errorholderSrc)
|
|
||||||
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
|
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +132,24 @@ export struct ImageKnifeComponent {
|
||||||
return //针对reuse场景,不显示历史图片
|
return //针对reuse场景,不显示历史图片
|
||||||
}
|
}
|
||||||
this.pixelMap = pixelMap
|
this.pixelMap = pixelMap
|
||||||
if (typeof this.pixelMap !== 'string' && this.imageKnifeOption.objectFit === ImageFit.Auto) { //针对静态图高度自适应
|
if (typeof this.pixelMap !== 'string') {
|
||||||
|
if (this.imageKnifeOption.objectFit === ImageFit.Auto) {
|
||||||
let info = await this.pixelMap.getImageInfo()
|
let info = await this.pixelMap.getImageInfo()
|
||||||
|
|
||||||
this.adaptiveWidth = this.currentWidth
|
this.adaptiveWidth = this.currentWidth
|
||||||
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
|
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
|
||||||
|
|
||||||
|
// if (this.currentWidth / this.currentHeight > info.size.width / info.size.height) {
|
||||||
|
// this.adaptiveWidth = this.currentWidth
|
||||||
|
// this.adaptiveHeight = info.size.height * this.currentWidth / this.currentHeight
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// this.adaptiveWidth = info.size.width * this.currentWidth / this.currentHeight
|
||||||
|
// this.adaptiveHeight = this.currentHeight
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//console.info("KKKKKKKKKKK:" + pixelMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestSource == ImageKnifeRequestSource.SRC) {
|
if (requestSource == ImageKnifeRequestSource.SRC) {
|
||||||
|
@ -166,3 +169,7 @@ export struct ImageKnifeComponent {
|
||||||
return this.request
|
return this.request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface KeyCanvas {
|
||||||
|
keyId: string
|
||||||
|
}
|
Loading…
Reference in New Issue