高度自适应方案修改、成功回调返回httpCode以及修复错误码httpCode无数据
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
parent
ba48f233a7
commit
fc6668cb0d
|
@ -1,3 +1,8 @@
|
|||
## 3.2.0-rc.7
|
||||
- Successful callback returns httpCode
|
||||
- Fix bug: Network error code httpCode returns no data
|
||||
- Fix bug: Height adaptation leads to fixed component height
|
||||
|
||||
## 3.2.0-rc.6
|
||||
- Support LogUtil to turn off log
|
||||
- Support set network request readTimeout and connectTimeout through ImageKnifeOption
|
||||
|
|
|
@ -350,6 +350,7 @@ struct TestImageKnifeCallbackPage {
|
|||
this.imageHeight = data.imageHeight;
|
||||
this.imageSize = data.bufSize;
|
||||
this.frameNum = data.frameCount;
|
||||
this.httpCode = data.httpCode
|
||||
this.decodeSize = JSON.stringify(data.decodeImages);
|
||||
this.imageType = data.type;
|
||||
this.reqEndTime = this.formatDate(data.timeInfo?.requestEndTime);
|
||||
|
@ -367,7 +368,7 @@ struct TestImageKnifeCallbackPage {
|
|||
this.errMsg = res;
|
||||
this.errPhase = data.errorInfo?.phase;
|
||||
this.errCode = data.errorInfo?.code;
|
||||
this.httpCode = data.errorInfo?.httpCode;
|
||||
this.httpCode = data.httpCode;
|
||||
this.reqEndTime = this.formatDate(data.timeInfo?.requestEndTime);
|
||||
this.diskStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
|
||||
this.diskEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"main": "index.ets",
|
||||
"repository": "https://gitee.com/openharmony-tpc/ImageKnife",
|
||||
"type": "module",
|
||||
"version": "3.2.0-rc.6",
|
||||
"version": "3.2.0-rc.7",
|
||||
"dependencies": {
|
||||
"@ohos/gpu_transform": "^1.0.2"
|
||||
},
|
||||
|
|
|
@ -101,17 +101,13 @@ export class ImageKnifeLoader {
|
|||
emitter.emit(Constants.CALLBACK_EMITTER + request.memoryKey, { data: { 'value': res } })
|
||||
}
|
||||
|
||||
static assembleError(data: ImageKnifeData | undefined, phase: string, code?: number,
|
||||
httpCode?: number): ImageKnifeData | undefined {
|
||||
static assembleError(data: ImageKnifeData | undefined, phase: string, code?: number): ImageKnifeData | undefined {
|
||||
let errorCallBackData = data?.errorInfo;
|
||||
if (!errorCallBackData) {
|
||||
return data;
|
||||
}
|
||||
errorCallBackData.phase = phase;
|
||||
errorCallBackData.code = code? code: 0;
|
||||
if (httpCode && httpCode != 0) {
|
||||
errorCallBackData.httpCode = httpCode;
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -533,19 +529,21 @@ export class ImageKnifeLoader {
|
|||
});
|
||||
|
||||
promise.then((data: number) => {
|
||||
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, undefined, data)
|
||||
callBackData.httpCode = data
|
||||
ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, undefined)
|
||||
callBackTimeInfo.netRequestEndTime = Date.now();
|
||||
if (data == 200 || data == 206 || data == 204) {
|
||||
resBuf = combineArrayBuffers(arrayBuffers)
|
||||
ImageKnifeLoader.FileCacheParseImage(request,resBuf,fileKey, callBackData)
|
||||
} else {
|
||||
loadError = 'HttpDownloadClient has error, http code =' + JSON.stringify(data)
|
||||
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE, data))
|
||||
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE))
|
||||
}
|
||||
}).catch((err: Error) => {
|
||||
}).catch((err: BusinessError) => {
|
||||
callBackData.httpCode = err.code
|
||||
loadError = 'HttpDownloadClient download ERROR : err = ' + JSON.stringify(err)
|
||||
callBackTimeInfo.netRequestEndTime = Date.now();
|
||||
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE, undefined))
|
||||
ImageKnifeLoader.makeEmptyResult(request,loadError, ImageKnifeLoader.assembleError(callBackData,LoadPhase.PHASE_NET, LoadPixelMapCode.IMAGE_HTTPS_LOAD_FAILED_CODE))
|
||||
});
|
||||
LogUtil.log('HttpDownloadClient.end:' + request.componentId + ',srcType:' + request.requestSource + ',' + request.componentVersion)
|
||||
return
|
||||
|
|
|
@ -27,7 +27,7 @@ export struct ImageKnifeComponent {
|
|||
@State pixelMap: PixelMap | string | ImageContent | undefined = ImageContent.EMPTY
|
||||
@State syncLoad: boolean = false
|
||||
@State adaptiveWidth: Length = '100%'
|
||||
@State adaptiveHeight: Length = '100%'
|
||||
@State adaptiveHeight: Length | undefined = '100%'
|
||||
@State objectFit: ImageFit = ImageFit.Contain
|
||||
private request: ImageKnifeRequest | undefined
|
||||
private lastWidth: number = 0
|
||||
|
@ -39,7 +39,7 @@ export struct ImageKnifeComponent {
|
|||
private currentContext: common.UIAbilityContext | undefined = undefined
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.objectFit = this.imageKnifeOption.objectFit === undefined ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
||||
this.objectFit = (this.imageKnifeOption.objectFit === undefined || this.imageKnifeOption.objectFit === ImageFit.Auto) ? ImageFit.Contain : this.imageKnifeOption.objectFit
|
||||
|
||||
if(this.syncLoad) { //针对部分消息列表最新消息的图片闪动问题,建议使用同步方式在aboutToAppear时加载图片
|
||||
let engineKey: IEngineKey = new DefaultEngineKey();
|
||||
|
@ -155,11 +155,9 @@ export struct ImageKnifeComponent {
|
|||
LogUtil.info('image load showPixelMap:' + this.request?.componentId + ',srcType:' + requestSource +
|
||||
',version:' + this.request?.componentVersion +
|
||||
',size:' + JSON.stringify(size))
|
||||
if (typeof this.pixelMap !== 'string') {
|
||||
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
|
||||
this.adaptiveHeight = this.currentWidth * size.height / size.width
|
||||
this.isImageFitAutoResize = true
|
||||
}
|
||||
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false && requestSource == ImageKnifeRequestSource.SRC) {
|
||||
this.adaptiveHeight = undefined
|
||||
this.isImageFitAutoResize = true
|
||||
}
|
||||
|
||||
if (requestSource == ImageKnifeRequestSource.SRC) {
|
||||
|
|
|
@ -26,6 +26,7 @@ export interface ImageKnifeData {
|
|||
imageHeight: number,
|
||||
bufSize?: number, // 图片的字节数
|
||||
type?:string,
|
||||
httpCode?: number, // 网络请求状态码及错误码
|
||||
imageAnimator?: Array<ImageFrameInfo>
|
||||
frameCount ?: number // 帧
|
||||
decodeImages?: Array<DecodeImageInfo> //Image组件或者ImageAnimator组件可以加载一张或者多张
|
||||
|
@ -48,7 +49,6 @@ export interface DecodeImageInfo {
|
|||
export interface ErrorInfo {
|
||||
phase: string, //图片加载阶段信息,如:网络加载阶段,缓存获取阶段及其解码阶段等
|
||||
code: number,
|
||||
httpCode?: number
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue