mirror of
https://github.com/status-im/react-native.git
synced 2025-01-30 03:05:44 +00:00
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:
parent
072ef0a0d4
commit
c95d3ef147
@ -4,15 +4,16 @@ android_library(
|
|||||||
name = 'textinput',
|
name = 'textinput',
|
||||||
srcs = glob(['*.java']),
|
srcs = glob(['*.java']),
|
||||||
deps = [
|
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/infer-annotations:infer-annotations'),
|
||||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
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 = [
|
visibility = [
|
||||||
'PUBLIC',
|
'PUBLIC',
|
||||||
|
@ -13,11 +13,9 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View.MeasureSpec;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.facebook.csslayout.CSSConstants;
|
|
||||||
import com.facebook.csslayout.CSSMeasureMode;
|
import com.facebook.csslayout.CSSMeasureMode;
|
||||||
import com.facebook.csslayout.CSSNode;
|
import com.facebook.csslayout.CSSNode;
|
||||||
import com.facebook.csslayout.MeasureOutput;
|
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.UIViewOperationQueue;
|
||||||
import com.facebook.react.uimanager.ViewDefaults;
|
import com.facebook.react.uimanager.ViewDefaults;
|
||||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
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.ReactTextShadowNode;
|
||||||
import com.facebook.react.views.text.ReactTextUpdate;
|
import com.facebook.react.views.text.ReactTextUpdate;
|
||||||
|
|
||||||
@ -91,21 +90,13 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
|||||||
editText.setLines(mNumberOfLines);
|
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.width = editText.getMeasuredWidth();
|
||||||
measureOutput.height = editText.getMeasuredHeight();
|
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
|
@Override
|
||||||
public void onBeforeLayout() {
|
public void onBeforeLayout() {
|
||||||
// We don't have to measure the text within the text input.
|
// We don't have to measure the text within the text input.
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user