From 242f5e91985f1b3b33c0b4cddc52e4678ecf5b3e Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Thu, 27 Oct 2016 10:52:09 -0700 Subject: [PATCH] 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 --- .../react/flat/FlatARTSurfaceViewManager.java | 5 ++--- .../main/java/com/facebook/react/flat/RCTText.java | 12 ++++-------- .../java/com/facebook/react/flat/RCTTextInput.java | 8 +++----- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewManager.java index 0ce91a60391..5a6cb05e031 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewManager.java @@ -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"); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java index 7211a8bb38e..f0ef5b8a84c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java @@ -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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java index a0edc926bf4..f30c72d7a76 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInput.java @@ -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