mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
BREAKING - Change measure() api to remove need for MeasureOutput allocation
Reviewed By: splhack Differential Revision: D4081037 fbshipit-source-id: 28adbcdd160cbd3f59a0fdd4b9f1200ae18678f1
This commit is contained in:
committed by
Facebook Github Bot
parent
bafc6ddbd1
commit
553f4371e0
@@ -487,15 +487,12 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
|
||||
MeasureOutput output = new MeasureOutput();
|
||||
mMeasureFunction.measure(
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
CSSMeasureMode.values()[widthMode],
|
||||
height,
|
||||
CSSMeasureMode.values()[heightMode],
|
||||
output);
|
||||
return ((long) output.width) << 32 | ((long) output.height);
|
||||
CSSMeasureMode.values()[heightMode]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,13 +12,15 @@ package com.facebook.csslayout;
|
||||
public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
|
||||
|
||||
interface MeasureFunction {
|
||||
void measure(
|
||||
/**
|
||||
* Return a value created by MeasureOutput.make(width, height);
|
||||
*/
|
||||
long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput);
|
||||
CSSMeasureMode heightMode);
|
||||
}
|
||||
|
||||
int getChildCount();
|
||||
|
||||
@@ -134,14 +134,11 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
|
||||
return mIsTextNode;
|
||||
}
|
||||
|
||||
MeasureOutput measure(MeasureOutput measureOutput, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
|
||||
long measure(float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
measureOutput.height = CSSConstants.UNDEFINED;
|
||||
measureOutput.width = CSSConstants.UNDEFINED;
|
||||
Assertions.assertNotNull(mMeasureFunction).measure(this, width, widthMode, height, heightMode, measureOutput);
|
||||
return measureOutput;
|
||||
return Assertions.assertNotNull(mMeasureFunction).measure(this, width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -560,22 +560,23 @@ public class LayoutEngine {
|
||||
} else {
|
||||
|
||||
// Measure the text under the current constraints.
|
||||
MeasureOutput measureDim = node.measure(
|
||||
|
||||
layoutContext.measureOutput,
|
||||
long measureOutput = node.measure(
|
||||
innerWidth,
|
||||
widthMeasureMode,
|
||||
innerHeight,
|
||||
heightMeasureMode
|
||||
);
|
||||
|
||||
int outputWidth = MeasureOutput.getWidth(measureOutput);
|
||||
int outputHeight = MeasureOutput.getHeight(measureOutput);
|
||||
|
||||
node.layout.measuredDimensions[DIMENSION_WIDTH] = boundAxis(node, CSS_FLEX_DIRECTION_ROW,
|
||||
(widthMeasureMode == CSSMeasureMode.UNDEFINED || widthMeasureMode == CSSMeasureMode.AT_MOST) ?
|
||||
measureDim.width + paddingAndBorderAxisRow :
|
||||
outputWidth + paddingAndBorderAxisRow :
|
||||
availableWidth - marginAxisRow);
|
||||
node.layout.measuredDimensions[DIMENSION_HEIGHT] = boundAxis(node, CSS_FLEX_DIRECTION_COLUMN,
|
||||
(heightMeasureMode == CSSMeasureMode.UNDEFINED || heightMeasureMode == CSSMeasureMode.AT_MOST) ?
|
||||
measureDim.height + paddingAndBorderAxisColumn :
|
||||
outputHeight + paddingAndBorderAxisColumn :
|
||||
availableHeight - marginAxisColumn);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,23 @@
|
||||
package com.facebook.csslayout;
|
||||
|
||||
/**
|
||||
* POJO to hold the output of the measure function.
|
||||
* Helpers for building measure output value.
|
||||
*/
|
||||
public class MeasureOutput {
|
||||
|
||||
public float width;
|
||||
public float height;
|
||||
public static long make(float width, float height) {
|
||||
return make((int) width, (int) height);
|
||||
}
|
||||
|
||||
public static long make(int width, int height) {
|
||||
return ((long) width) << 32 | ((long) height);
|
||||
}
|
||||
|
||||
public static int getWidth(long measureOutput) {
|
||||
return (int) (0xFFFFFFFF & (measureOutput >> 32));
|
||||
}
|
||||
|
||||
public static int getHeight(long measureOutput) {
|
||||
return (int) (0xFFFFFFFF & measureOutput);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user