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
@@ -28,13 +28,12 @@ public class ARTSurfaceViewManager extends
|
||||
|
||||
private static final CSSNodeAPI.MeasureFunction MEASURE_FUNCTION = new CSSNodeAPI.MeasureFunction() {
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
throw new IllegalStateException("SurfaceView should have explicit width and height set");
|
||||
}
|
||||
};
|
||||
|
||||
+3
-5
@@ -52,13 +52,12 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
|
||||
if (!mMeasured.contains(style)) {
|
||||
ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
|
||||
@@ -71,7 +70,6 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAP
|
||||
mMeasured.add(style);
|
||||
}
|
||||
|
||||
measureOutput.height = mHeight.get(style);
|
||||
measureOutput.width = mWidth.get(style);
|
||||
return MeasureOutput.make(mWidth.get(style), mHeight.get(style));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +50,12 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
if (!mMeasured) {
|
||||
SeekBar reactSlider = new ReactSlider(getThemedContext(), null, STYLE);
|
||||
final int spec = View.MeasureSpec.makeMeasureSpec(
|
||||
@@ -67,8 +66,8 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
|
||||
mHeight = reactSlider.getMeasuredHeight();
|
||||
mMeasured = true;
|
||||
}
|
||||
measureOutput.width = mWidth;
|
||||
measureOutput.height = mHeight;
|
||||
|
||||
return MeasureOutput.make(mWidth, mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -44,13 +44,12 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
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
|
||||
@@ -64,8 +63,8 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
||||
mHeight = reactSwitch.getMeasuredHeight();
|
||||
mMeasured = true;
|
||||
}
|
||||
measureOutput.width = mWidth;
|
||||
measureOutput.height = mHeight;
|
||||
|
||||
return MeasureOutput.make(mWidth, mHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,13 +221,12 @@ public class ReactTextShadowNode extends LayoutShadowNode {
|
||||
private static final CSSNodeAPI.MeasureFunction TEXT_MEASURE_FUNCTION =
|
||||
new CSSNodeAPI.MeasureFunction() {
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
|
||||
ReactTextShadowNode reactCSSNode = (ReactTextShadowNode) node;
|
||||
TextPaint textPaint = sTextPaintInstance;
|
||||
@@ -279,11 +278,13 @@ public class ReactTextShadowNode extends LayoutShadowNode {
|
||||
true);
|
||||
}
|
||||
|
||||
measureOutput.height = layout.getHeight();
|
||||
measureOutput.width = layout.getWidth();
|
||||
if (reactCSSNode.mNumberOfLines != UNSET &&
|
||||
reactCSSNode.mNumberOfLines < layout.getLineCount()) {
|
||||
measureOutput.height = layout.getLineBottom(reactCSSNode.mNumberOfLines - 1);
|
||||
return MeasureOutput.make(
|
||||
layout.getWidth(),
|
||||
layout.getLineBottom(reactCSSNode.mNumberOfLines - 1));
|
||||
} else {
|
||||
return MeasureOutput.make(layout.getWidth(), layout.getHeight());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+4
-5
@@ -71,13 +71,12 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
// measure() should never be called before setThemedContext()
|
||||
EditText editText = Assertions.assertNotNull(mEditText);
|
||||
|
||||
@@ -104,8 +103,8 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
||||
editText.measure(
|
||||
MeasureUtil.getMeasureSpec(width, widthMode),
|
||||
MeasureUtil.getMeasureSpec(height, heightMode));
|
||||
measureOutput.width = editText.getMeasuredWidth();
|
||||
measureOutput.height = editText.getMeasuredHeight();
|
||||
|
||||
return MeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user