新增aspectRatio参数, 修复某些情况下组件内的 Image 加载图片成功后只有componentWith, 但是componentHeight=0的情况
This commit is contained in:
parent
b3114dd47b
commit
8c025e5d02
|
@ -50,7 +50,7 @@ struct SingleImage {
|
|||
loadSrc: $r("app.media.svgSample"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain
|
||||
objectFit: ImageFit.Contain,
|
||||
})
|
||||
}).width(100).height(100)
|
||||
.onClick(()=>{
|
||||
|
@ -67,6 +67,18 @@ struct SingleImage {
|
|||
objectFit: ImageFit.Contain
|
||||
})
|
||||
}).width(100).height(100)
|
||||
Text("测试aspectRatio")
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
loadSrc: this.localFile,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain,
|
||||
aspectRatio: 1.5
|
||||
})
|
||||
}).width(100).height(100).backgroundColor(Color.Red)
|
||||
Text("网络图片")
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
|
|
|
@ -90,6 +90,7 @@ interface ImageOption {
|
|||
onLoadListener?: OnLoadCallBack | undefined;
|
||||
onComplete?:(event:EventImage | undefined) => void
|
||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||
aspectRatio?: number;
|
||||
}
|
||||
@ObservedV2
|
||||
export class ImageKnifeOption {
|
||||
|
@ -121,6 +122,7 @@ export class ImageKnifeOption {
|
|||
onLoadListener?: OnLoadCallBack | undefined;
|
||||
onComplete?:(event:EventImage | undefined) => void
|
||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||
aspectRatio?: number;
|
||||
constructor(option?:ImageOption) {
|
||||
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc
|
||||
this.placeholderSrc = option?.placeholderSrc
|
||||
|
@ -141,6 +143,7 @@ export class ImageKnifeOption {
|
|||
this.onLoadListener = option?.onLoadListener
|
||||
this.onComplete = option?.onComplete
|
||||
this.drawingColorFilter = option?.drawingColorFilter
|
||||
this.aspectRatio = option?.aspectRatio
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ export struct ImageKnifeComponent {
|
|||
.border(this.imageKnifeOption.border)
|
||||
.syncLoad(this.syncLoad)
|
||||
.draggable(false)
|
||||
.aspectRatio(this.imageKnifeOption.aspectRatio)
|
||||
.onComplete(this.imageKnifeOption.onComplete)
|
||||
.onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => {
|
||||
this.currentWidth = newValue.width as number
|
||||
|
|
Loading…
Reference in New Issue