mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Specs: introduce layoutDescendants() to avoid work when a layout manager is unaffected by its childrens' intrinsic dimensions Examples: update for layoutDescendants() change Specs: add "lifetime" to resolver settings so that a transition can avoid having to dirty every consumer of the property every frame when it only needs to update the objects that are changing that frame Specs: expose the parents on AbstractStyleDeclarationList subclasses Specs: fix documentation around autoreap Specs: fix definition of setProperty() Specs: clean up the dimension-related logic of layout managers Review URL: https://codereview.chromium.org/850593003
79 lines
2.4 KiB
Plaintext
79 lines
2.4 KiB
Plaintext
SKY MODULE
|
|
<import src="sky:core" as="sky"/>
|
|
<!--
|
|
! this module provides trivial vertical block layout
|
|
! no margins, padding, borders, etc
|
|
!-->
|
|
<script>
|
|
module.exports.BlockLayoutManager = class BlockLayoutManager extends sky.LayoutManager {
|
|
function layout(width, height) {
|
|
if (width == null)
|
|
width = this.getIntrinsicWidth().value;
|
|
let autoHeight = false;
|
|
if (height == null) {
|
|
height = 0;
|
|
autoHeight = true;
|
|
}
|
|
this.assumeDimensions(width, height);
|
|
let children = this.walkChildren();
|
|
let loop = children.next();
|
|
let y = 0;
|
|
while (!loop.done) {
|
|
let child = loop.value;
|
|
if (child.needsLayout || child.descendantNeedsLayout) {
|
|
let dims = child.layoutManager.layout(width, null);
|
|
this.setChildSize(child, dims.width, dims.height);
|
|
}
|
|
this.setChildPosition(child, 0, y);
|
|
y += child.height;
|
|
loop = children.next();
|
|
}
|
|
if (autoHeight)
|
|
height = y;
|
|
this.markAsLaidOut();
|
|
return {
|
|
width: width,
|
|
height: height,
|
|
}
|
|
}
|
|
function layoutDescendants() {
|
|
this.layout(node.width, node.height);
|
|
}
|
|
function getIntrinsicWidth() {
|
|
let width = this.node.getProperty('width');
|
|
if (typeof width != 'number') {
|
|
// e.g. width: auto
|
|
width = 0;
|
|
let children = this.walkChildren();
|
|
let loop = children.next();
|
|
while (!loop.done) {
|
|
let child = loop.value;
|
|
let childWidth = child.layoutManager.getIntrinsicWidth();
|
|
if (width < childWidth.value)
|
|
width = childWidth.value;
|
|
loop = children.next();
|
|
}
|
|
}
|
|
return super(width); // applies and provides our own min-width/max-width rules
|
|
}
|
|
function getIntrinsicHeight() {
|
|
let height = this.node.getProperty('height');
|
|
if (typeof height != 'number') {
|
|
// e.g. height: auto
|
|
height = 0;
|
|
let children = this.walkChildren();
|
|
let loop = children.next();
|
|
while (!loop.done) {
|
|
let child = loop.value;
|
|
let childHeight = child.layoutManager.getIntrinsicHeight();
|
|
if (height < childHeight.value)
|
|
height = childHeight.value;
|
|
loop = children.next();
|
|
}
|
|
}
|
|
return super(height); // applies and provides our own min-height/max-height rules
|
|
}
|
|
}
|
|
sky.registerLayoutManager('block', module.exports.BlockLayoutManager);
|
|
</script>
|