diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java index a5519e129..46827fb92 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java @@ -7,7 +7,7 @@ */ // NOTE: this file is auto-copied from https://github.com/facebook/css-layout -// @generated SignedSource<<4b95f0548441afa1e91e957a93fa6f0b>> +// @generated SignedSource<<1f520d46cbfddbbea0661a8fb6a00748>> package com.facebook.csslayout; @@ -56,7 +56,7 @@ public class CSSNode { * * NB: measure is NOT guaranteed to be threadsafe/re-entrant safe! */ - public void measure(CSSNode node, float width, MeasureOutput measureOutput); + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput); } // VisibleForTesting @@ -128,13 +128,13 @@ public class CSSNode { return mMeasureFunction != null; } - /*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width) { + /*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width, float height) { if (!isMeasureDefined()) { throw new RuntimeException("Measure function isn't defined!"); } measureOutput.height = CSSConstants.UNDEFINED; measureOutput.width = CSSConstants.UNDEFINED; - Assertions.assertNotNull(mMeasureFunction).measure(this, width, measureOutput); + Assertions.assertNotNull(mMeasureFunction).measure(this, width, height, measureOutput); return measureOutput; } @@ -143,7 +143,7 @@ public class CSSNode { */ public void calculateLayout(CSSLayoutContext layoutContext) { layout.resetResult(); - LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, null); + LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, CSSConstants.UNDEFINED, null); } /** diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CachedCSSLayout.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CachedCSSLayout.java index 97ef4886f..6d631d37c 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CachedCSSLayout.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CachedCSSLayout.java @@ -7,7 +7,7 @@ */ // NOTE: this file is auto-copied from https://github.com/facebook/css-layout -// @generated SignedSource<<8276834951a75286a0b6d4a980bc43ce>> +// @generated SignedSource<> package com.facebook.csslayout; @@ -21,4 +21,5 @@ public class CachedCSSLayout extends CSSLayout { public float requestedWidth = CSSConstants.UNDEFINED; public float requestedHeight = CSSConstants.UNDEFINED; public float parentMaxWidth = CSSConstants.UNDEFINED; + public float parentMaxHeight = CSSConstants.UNDEFINED; } diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/LayoutEngine.java b/ReactAndroid/src/main/java/com/facebook/csslayout/LayoutEngine.java index 30e14f052..711aed2ab 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/LayoutEngine.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/LayoutEngine.java @@ -7,7 +7,7 @@ */ // NOTE: this file is auto-copied from https://github.com/facebook/css-layout -// @generated SignedSource<> +// @generated SignedSource<> package com.facebook.csslayout; @@ -19,7 +19,7 @@ import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT; import static com.facebook.csslayout.CSSLayout.POSITION_TOP; /** - * Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float)}. + * Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float, float)}. */ public class LayoutEngine { @@ -109,7 +109,7 @@ public class LayoutEngine { return; } // We only run if there's a width or height defined - if (Float.isNaN(node.style.dimensions[dim[axis]]) || + if (Float.isNaN(node.style.dimensions[dim[axis]]) || node.style.dimensions[dim[axis]] <= 0.0) { return; } @@ -183,7 +183,7 @@ public class LayoutEngine { return node.isMeasureDefined(); } - static boolean needsRelayout(CSSNode node, float parentMaxWidth) { + static boolean needsRelayout(CSSNode node, float parentMaxWidth, float parentMaxHeight) { return node.isDirty() || !FloatUtil.floatsEqual( node.lastLayout.requestedHeight, @@ -191,20 +191,23 @@ public class LayoutEngine { !FloatUtil.floatsEqual( node.lastLayout.requestedWidth, node.layout.dimensions[DIMENSION_WIDTH]) || - !FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth); + !FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth) || + !FloatUtil.floatsEqual(node.lastLayout.parentMaxHeight, parentMaxHeight); } /*package*/ static void layoutNode( CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, + float parentMaxHeight, CSSDirection parentDirection) { - if (needsRelayout(node, parentMaxWidth)) { + if (needsRelayout(node, parentMaxWidth, parentMaxHeight)) { node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH]; node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT]; node.lastLayout.parentMaxWidth = parentMaxWidth; + node.lastLayout.parentMaxHeight = parentMaxHeight; - layoutNodeImpl(layoutContext, node, parentMaxWidth, parentDirection); + layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection); node.lastLayout.copy(node.layout); } else { node.layout.copy(node.lastLayout); @@ -217,6 +220,7 @@ public class LayoutEngine { CSSLayoutContext layoutContext, CSSNode node, float parentMaxWidth, + float parentMaxHeight, CSSDirection parentDirection) { for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) { node.getChildAt(i).layout.resetResult(); @@ -251,6 +255,7 @@ public class LayoutEngine { // invocations during the layout calculation. int childCount = node.getChildCount(); float paddingAndBorderAxisResolvedRow = ((node.style.padding.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.border.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis])) + (node.style.padding.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]) + node.style.border.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis]))); + float paddingAndBorderAxisColumn = ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); if (isMeasureDefined(node)) { boolean isResolvedRowDimDefined = !Float.isNaN(node.layout.dimensions[dim[resolvedRowAxis]]); @@ -266,6 +271,17 @@ public class LayoutEngine { } width -= paddingAndBorderAxisResolvedRow; + float height = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + height = node.style.dimensions[DIMENSION_HEIGHT]; + } else if (!Float.isNaN(node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]])) { + height = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]; + } else { + height = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])); + } + height -= ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); + // We only need to give a dimension for the text if we haven't got any // for it computed yet. It can either be from the style attribute or because // the element is flexible. @@ -278,7 +294,8 @@ public class LayoutEngine { MeasureOutput measureDim = node.measure( layoutContext.measureOutput, - width + width, + height ); if (isRowUndefined) { node.layout.dimensions[DIMENSION_WIDTH] = measureDim.width + @@ -286,7 +303,7 @@ public class LayoutEngine { } if (isColumnUndefined) { node.layout.dimensions[DIMENSION_HEIGHT] = measureDim.height + - ((node.style.padding.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN])) + (node.style.padding.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]) + node.style.border.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]))); + paddingAndBorderAxisColumn; } } if (childCount == 0) { @@ -367,6 +384,7 @@ public class LayoutEngine { float crossDim = 0; float maxWidth; + float maxHeight; for (i = startLine; i < childCount; ++i) { child = node.getChildAt(i); child.lineIndex = linesCount; @@ -447,6 +465,8 @@ public class LayoutEngine { } else { maxWidth = CSSConstants.UNDEFINED; + maxHeight = CSSConstants.UNDEFINED; + if (!isMainRowDirection) { if ((!Float.isNaN(node.style.dimensions[dim[resolvedRowAxis]]) && node.style.dimensions[dim[resolvedRowAxis]] >= 0.0)) { maxWidth = node.layout.dimensions[dim[resolvedRowAxis]] - @@ -456,11 +476,20 @@ public class LayoutEngine { (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) - paddingAndBorderAxisResolvedRow; } + } else { + if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] - + paddingAndBorderAxisColumn; + } else { + maxHeight = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) - + paddingAndBorderAxisColumn; + } } // This is the main recursive call. We layout non flexible children. if (alreadyComputedNextLayout == 0) { - layoutNode(layoutContext, child, maxWidth, direction); + layoutNode(layoutContext, child, maxWidth, maxHeight, direction); } // Absolute positioned elements do not take part of the layout, so we @@ -590,9 +619,18 @@ public class LayoutEngine { (node.style.margin.getWithFallback(leadingSpacing[resolvedRowAxis], leading[resolvedRowAxis]) + node.style.margin.getWithFallback(trailingSpacing[resolvedRowAxis], trailing[resolvedRowAxis])) - paddingAndBorderAxisResolvedRow; } + maxHeight = CSSConstants.UNDEFINED; + if ((!Float.isNaN(node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]) && node.style.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] >= 0.0)) { + maxHeight = node.layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]] - + paddingAndBorderAxisColumn; + } else if (isMainRowDirection) { + maxHeight = parentMaxHeight - + (node.style.margin.getWithFallback(leadingSpacing[CSS_FLEX_DIRECTION_COLUMN], leading[CSS_FLEX_DIRECTION_COLUMN]) + node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN])) - + paddingAndBorderAxisColumn; + } // And we recursively call the layout algorithm for this child - layoutNode(layoutContext, currentFlexChild, maxWidth, direction); + layoutNode(layoutContext, currentFlexChild, maxWidth, maxHeight, direction); child = currentFlexChild; currentFlexChild = currentFlexChild.nextFlexChild; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/README b/ReactAndroid/src/main/java/com/facebook/csslayout/README index 4916c2218..955473ba0 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/README +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/README @@ -1,7 +1,7 @@ The source of truth for css-layout is: https://github.com/facebook/css-layout The code here should be kept in sync with GitHub. -HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/d3b702e1ad0925f8683ce3039be8e493abbf179b +HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/219bdaed15c16bbf7c1f2bab17ad629d04cc4199 There is generated code in: - README (this file) diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/README.facebook b/ReactAndroid/src/main/java/com/facebook/csslayout/README.facebook index b7b2a9e90..8d78b2695 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/README.facebook +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/README.facebook @@ -1,7 +1,7 @@ The source of truth for css-layout is: https://github.com/facebook/css-layout The code here should be kept in sync with GitHub. -HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/d3b702e1ad0925f8683ce3039be8e493abbf179b +HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/219bdaed15c16bbf7c1f2bab17ad629d04cc4199 There is generated code in: - README.facebook (this file) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java index dc49c4aa1..28309d79b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java @@ -51,7 +51,7 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNode.M } @Override - public void measure(CSSNode node, float width, MeasureOutput measureOutput) { + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) { final int style = ReactProgressBarViewManager.getStyleFromString(getStyle()); if (!mMeasured.contains(style)) { ProgressBar progressBar = new ProgressBar(getThemedContext(), null, style); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java index 115cc9621..60b71f0eb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java @@ -45,7 +45,7 @@ public class ReactSwitchManager extends SimpleViewManager { } @Override - public void measure(CSSNode node, float width, MeasureOutput measureOutput) { + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) { if (!mMeasured) { // Create a switch with the default config and measure it; since we don't (currently) // support setting custom switch text, this is fine, as all switches will measure the same diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 1e4286f78..e6e19ad8c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -194,7 +194,7 @@ public class ReactTextShadowNode extends LayoutShadowNode { private static final CSSNode.MeasureFunction TEXT_MEASURE_FUNCTION = new CSSNode.MeasureFunction() { @Override - public void measure(CSSNode node, float width, MeasureOutput measureOutput) { + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) { // TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic) ReactTextShadowNode reactCSSNode = (ReactTextShadowNode) node; TextPaint textPaint = sTextPaintInstance; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index 47b3f48fd..2a37f82f1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -68,7 +68,7 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements } @Override - public void measure(CSSNode node, float width, MeasureOutput measureOutput) { + public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) { // measure() should never be called before setThemedContext() EditText editText = Assertions.assertNotNull(mEditText);