From c95d3ef147325257097ebe81cfdd590e781f3202 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 22 Jun 2016 14:58:07 -0700 Subject: [PATCH] Fix measure callback for TextInput on Nodes Summary: Add a MeasureUtil class Reviewed By: emilsjolander Differential Revision: D3467598 fbshipit-source-id: 3ef0da1e4ef16c1f9756653d0aa2e8aa5a598eb1 --- .../com/facebook/react/views/textinput/BUCK | 15 +++++++------- .../textinput/ReactTextInputShadowNode.java | 17 ++++------------ .../react/views/view/MeasureUtil.java | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK index 925dc15d3..eb663b0fa 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK @@ -4,15 +4,16 @@ android_library( name = 'textinput', srcs = glob(['*.java']), deps = [ - react_native_target('java/com/facebook/react/bridge:bridge'), - react_native_target('java/com/facebook/react/common:common'), - react_native_target('java/com/facebook/react/views/text:text'), - react_native_target('java/com/facebook/csslayout:csslayout'), - react_native_target('java/com/facebook/react/modules/core:core'), - react_native_target('java/com/facebook/react/uimanager:uimanager'), - react_native_target('java/com/facebook/react/uimanager/annotations:annotations'), react_native_dep('third-party/java/infer-annotations:infer-annotations'), react_native_dep('third-party/java/jsr-305:jsr-305'), + react_native_target('java/com/facebook/csslayout:csslayout'), + react_native_target('java/com/facebook/react/bridge:bridge'), + react_native_target('java/com/facebook/react/common:common'), + react_native_target('java/com/facebook/react/modules/core:core'), + react_native_target('java/com/facebook/react/uimanager/annotations:annotations'), + react_native_target('java/com/facebook/react/uimanager:uimanager'), + react_native_target('java/com/facebook/react/views/text:text'), + react_native_target('java/com/facebook/react/views/view:view'), ], visibility = [ 'PUBLIC', diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index ad2ea0b55..4bb885156 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -13,11 +13,9 @@ import javax.annotation.Nullable; import android.text.Spannable; import android.util.TypedValue; -import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.widget.EditText; -import com.facebook.csslayout.CSSConstants; import com.facebook.csslayout.CSSMeasureMode; import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.MeasureOutput; @@ -29,6 +27,7 @@ import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.ViewDefaults; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.views.view.MeasureUtil; import com.facebook.react.views.text.ReactTextShadowNode; import com.facebook.react.views.text.ReactTextUpdate; @@ -91,21 +90,13 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements editText.setLines(mNumberOfLines); } - editText.measure(getMeasureSpec(width, widthMode), getMeasureSpec(height, heightMode)); + editText.measure( + MeasureUtil.getMeasureSpec(width, widthMode), + MeasureUtil.getMeasureSpec(height, heightMode)); measureOutput.width = editText.getMeasuredWidth(); measureOutput.height = editText.getMeasuredHeight(); } - private int getMeasureSpec(float size, CSSMeasureMode mode) { - if (mode == CSSMeasureMode.EXACTLY) { - return MeasureSpec.makeMeasureSpec((int) size, MeasureSpec.EXACTLY); - } else if (mode == CSSMeasureMode.AT_MOST) { - return MeasureSpec.makeMeasureSpec((int) size, MeasureSpec.AT_MOST); - } else { - return MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - } - } - @Override public void onBeforeLayout() { // We don't have to measure the text within the text input. diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java new file mode 100644 index 000000000..14195a928 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java @@ -0,0 +1,20 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +package com.facebook.react.views.view; + +import android.view.View; + +import com.facebook.csslayout.CSSMeasureMode; + +public class MeasureUtil { + + public static int getMeasureSpec(float size, CSSMeasureMode mode) { + if (mode == CSSMeasureMode.EXACTLY) { + return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.EXACTLY); + } else if (mode == CSSMeasureMode.AT_MOST) { + return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.AT_MOST); + } else { + return View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); + } + } +}