Fix measure callback for TextInput on Nodes

Summary: Add a MeasureUtil class

Reviewed By: emilsjolander

Differential Revision: D3467598

fbshipit-source-id: 3ef0da1e4ef16c1f9756653d0aa2e8aa5a598eb1
This commit is contained in:
Ahmed El-Helw 2016-06-22 14:58:07 -07:00 committed by Facebook Github Bot 8
parent 072ef0a0d4
commit c95d3ef147
3 changed files with 32 additions and 20 deletions

View File

@ -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',

View File

@ -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.

View File

@ -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);
}
}
}