Compare commits

..

2 Commits

Author SHA1 Message Date
Madi f3d8c91424
Pre Merge pull request !433 from Madi/master 2024-11-25 09:46:09 +00:00
madixin e29c659e89 1. ImageFit.Auto 组件宽度更改后自动支持自适应高度,并补充样例。
2.修复onLoadStart会调用2次的bug

Signed-off-by: madixin <madixin@huawei.com>
2024-11-25 17:45:55 +08:00
2 changed files with 13 additions and 15 deletions

View File

@ -15,43 +15,42 @@
import { import {
ImageKnifeComponent, ImageKnifeComponent,
ImageKnifeData, ImageKnifeData,
ImageKnifeRequest ImageKnifeRequest, LogUtil
} from '@ohos/libraryimageknife'; } from '@ohos/libraryimageknife';
@Entry @Entry
@Component @Component
struct AutoImageFit { struct AutoImageFit {
@State width1: Length = "100%" @State width1: Length = '100%'
build() { build() {
Scroll() { Scroll() {
Column() { Column() {
Button($r('app.string.adjust_size')).onClick(() => { Button($r('app.string.adjust_size')).onClick(() => {
if (this.width1.toString() == "100%") { if (this.width1.toString() == '100%') {
this.width1 = "60%" this.width1 = '60%'
} else { } else {
this.width1 = "100%" this.width1 = '100%'
} }
}).width("100%") }).width('100%')
Text("Image") Text('Image')
Image("https://img1.baidu.com/it/u=313035107,662730619&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1233").width("100%").objectFit(ImageFit.Auto) Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg').width('100%').objectFit(ImageFit.Auto)
Text("ImageKnife") Text('ImageKnife')
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: {
loadSrc: "https://img1.baidu.com/it/u=313035107,662730619&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1233", loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
objectFit: ImageFit.Auto, objectFit: ImageFit.Auto,
onLoadListener: { onLoadListener: {
onLoadStart: (request?: ImageKnifeRequest) => { onLoadStart: (request?: ImageKnifeRequest) => {
console.info("11111111111111111111 onLoadStart") LogUtil.info('onLoadStart')
}, },
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData, onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
request?: ImageKnifeRequest) => { request?: ImageKnifeRequest) => {
console.info("11111111111111111111 onLoadSuccess") LogUtil.info('onLoadSuccess')
} }
} }
} }
}).width("100%") }).width('100%')
}.width(this.width1).border({ width: 1 }) }.width(this.width1).border({ width: 1 })
} }

View File

@ -152,7 +152,6 @@ export struct ImageKnifeComponent {
this.pixelMap = pixelMap this.pixelMap = pixelMap
if (typeof this.pixelMap !== 'string') { if (typeof this.pixelMap !== 'string') {
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) { if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
// this.adaptiveWidth = this.currentWidth
this.adaptiveHeight = this.currentWidth * size.height / size.width this.adaptiveHeight = this.currentWidth * size.height / size.width
this.isImageFitAutoResize = true this.isImageFitAutoResize = true
} }