h5:VLayout and HLayout's child alignment

This commit is contained in:
pengfei.zhou
2019-12-26 14:47:11 +08:00
committed by osborn
parent 102bf100ce
commit a4bbf2bb76
7 changed files with 113 additions and 9 deletions

View File

@@ -48,6 +48,13 @@ export class DoricHLayoutNode extends DoricGroupViewNode {
+ (e.layoutConfig?.margin?.right || 0))
e.view.style.marginTop = toPixelString(e.layoutConfig?.margin?.top || 0)
e.view.style.marginBottom = toPixelString(e.layoutConfig?.margin?.bottom || 0)
if ((e.layoutConfig.alignment & TOP) === TOP) {
e.view.style.alignSelf = "flex-start"
} else if ((e.layoutConfig.alignment & BOTTOM) === BOTTOM) {
e.view.style.alignSelf = "flex-end"
} else if ((e.layoutConfig.alignment & CENTER_Y) === CENTER_Y) {
e.view.style.alignSelf = "center"
}
})
}
}

View File

@@ -10,7 +10,25 @@ export class DoricStackNode extends DoricGroupViewNode {
layout() {
super.layout()
this.configOffset()
Promise.resolve().then(_ => {
this.configSize()
this.configOffset()
})
}
configSize() {
if (this.layoutConfig.widthSpec === LayoutSpec.WRAP_CONTENT) {
const width = this.childNodes.reduce((prev, current) => {
return Math.max(prev, current.view.offsetWidth)
}, 0)
this.view.style.width = toPixelString(width)
}
if (this.layoutConfig.heightSpec === LayoutSpec.WRAP_CONTENT) {
const height = this.childNodes.reduce((prev, current) => {
return Math.max(prev, current.view.offsetHeight)
}, 0)
this.view.style.height = toPixelString(height)
}
}
configOffset() {

View File

@@ -48,6 +48,13 @@ export class DoricVLayoutNode extends DoricGroupViewNode {
+ (e.layoutConfig?.margin?.bottom || 0))
e.view.style.marginLeft = toPixelString(e.layoutConfig?.margin?.left || 0)
e.view.style.marginRight = toPixelString(e.layoutConfig?.margin?.right || 0)
if ((e.layoutConfig.alignment & LEFT) === LEFT) {
e.view.style.alignSelf = "flex-start"
} else if ((e.layoutConfig.alignment & RIGHT) === RIGHT) {
e.view.style.alignSelf = "flex-end"
} else if ((e.layoutConfig.alignment & CENTER_X) === CENTER_X) {
e.view.style.alignSelf = "center"
}
})
}
}

View File

@@ -110,6 +110,7 @@ export abstract class DoricViewNode {
this.reusable = superNode.reusable
}
this.view = this.build()
this.view.style.overflow = "hidden"
}
abstract build(): HTMLElement