mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-17 12:19:12 +08:00
BREAKING - Change measure() api to remove need for MeasureOutput allocation
Summary: This is an API breaking change done to allow us to avoid an allocation during measurement. Instead we do the same trick as is done when passing measure results to C, we path them into a long. Reviewed By: splhack Differential Revision: D4081037
This commit is contained in:
committed by
Ahmed El-Helw
parent
7af3331171
commit
242f5e9198
@@ -23,13 +23,12 @@ import com.facebook.react.views.art.ARTSurfaceView;
|
||||
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,21 +73,18 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measure(
|
||||
public long measure(
|
||||
CSSNodeAPI node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode,
|
||||
MeasureOutput measureOutput) {
|
||||
CSSMeasureMode heightMode) {
|
||||
|
||||
CharSequence text = getText();
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
// to indicate that we don't have anything to display
|
||||
mText = null;
|
||||
measureOutput.width = 0;
|
||||
measureOutput.height = 0;
|
||||
return;
|
||||
return MeasureOutput.make(0, 0);
|
||||
} else {
|
||||
mText = text;
|
||||
}
|
||||
@@ -112,8 +109,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
mDrawCommand = new DrawTextLayout(layout);
|
||||
}
|
||||
|
||||
measureOutput.width = mDrawCommand.getLayoutWidth();
|
||||
measureOutput.height = mDrawCommand.getLayoutHeight();
|
||||
return MeasureOutput.make(mDrawCommand.getLayoutWidth(), mDrawCommand.getLayoutHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -75,13 +75,12 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@@ -103,8 +102,7 @@ public class RCTTextInput extends RCTVirtualText implements AndroidView, CSSNode
|
||||
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