updated css-layout and fixed callsites
Reviewed By: foghina Differential Revision: D2757965 fb-gh-sync-id: 061ff38ae59783edb36ff66516866e4a22fd6e25
This commit is contained in:
parent
2ac0157a24
commit
c46936a00d
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
|
||||
// @generated SignedSource<<8276834951a75286a0b6d4a980bc43ce>>
|
||||
// @generated SignedSource<<e2f8139d4c50e4d2a9281a4587f8c095>>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
|
||||
// @generated SignedSource<<c4feb337df98136c86629cf72c93f049>>
|
||||
// @generated SignedSource<<df03fd95c4520badeed398c76e70242d>>
|
||||
|
||||
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 {
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue