Add isDirty support

This commit is contained in:
Devon Govett
2015-10-04 14:11:55 -07:00
parent 221510cfcf
commit e9d880a105

View File

@@ -63,7 +63,7 @@ var computeLayout = (function() {
// properties. For the JavaScript version this function adds these properties // properties. For the JavaScript version this function adds these properties
// if they don't already exist. // if they don't already exist.
function fillNodes(node) { function fillNodes(node) {
if (!node.layout) { if (!node.layout || node.isDirty) {
node.layout = { node.layout = {
width: undefined, width: undefined,
height: undefined, height: undefined,
@@ -1124,7 +1124,8 @@ var computeLayout = (function() {
} }
function layoutNode(node, parentMaxWidth, parentDirection) { function layoutNode(node, parentMaxWidth, parentDirection) {
if (!node.lastLayout || if (node.isDirty ||
!node.lastLayout ||
node.lastLayout.requestedHeight !== node.layout.height || node.lastLayout.requestedHeight !== node.layout.height ||
node.lastLayout.requestedWidth !== node.layout.width || node.lastLayout.requestedWidth !== node.layout.width ||
node.lastLayout.parentMaxWidth !== parentMaxWidth) { node.lastLayout.parentMaxWidth !== parentMaxWidth) {
@@ -1137,11 +1138,23 @@ var computeLayout = (function() {
node.lastLayout.requestedHeight = node.layout.height; node.lastLayout.requestedHeight = node.layout.height;
node.lastLayout.parentMaxWidth = parentMaxWidth; node.lastLayout.parentMaxWidth = parentMaxWidth;
// Reset child layouts
node.children.forEach(function(child) {
child.layout.width = undefined;
child.layout.height = undefined;
child.layout.top = 0;
child.layout.left = 0;
child.layout.bottom = 0;
child.layout.right = 0;
});
layoutNodeImpl(node, parentMaxWidth, parentDirection); layoutNodeImpl(node, parentMaxWidth, parentDirection);
for (var key in node.layout) { for (var key in node.layout) {
node.lastLayout[key] = node.layout[key]; node.lastLayout[key] = node.layout[key];
} }
node.isDirty = false;
} else { } else {
for (var key in node.layout) { for (var key in node.layout) {
node.layout[key] = node.lastLayout[key]; node.layout[key] = node.lastLayout[key];