From 86f24ccf71f4c41904838c8c7e13268c300fd745 Mon Sep 17 00:00:00 2001 From: Jiaqi Wu Date: Thu, 19 Jul 2018 17:06:14 -0700 Subject: [PATCH] Fix placeholder clipping issue Summary: Problem: The first ReactTextInputShadowNode layout calculation didn't consider the placeholder. When the layout with placeholder was actually being measured, its height was constraint by the previously calculated height, causing long placeholder content to be clipped. Fix: Access the placeholder property in ReactTextInputShadowNode, set the dummyEditText's hint with placeholder before ReactTextInputShadowNode's first measurement. Reviewed By: mdvacca Differential Revision: D8903108 fbshipit-source-id: 8f3e518d0395ac875807f9ea989a0b5bbe4b2a26 --- .../textinput/ReactTextInputShadowNode.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 28c559afbc12de..20807f81fbc518 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 @@ -41,9 +41,11 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode private @Nullable ReactTextInputLocalData mLocalData; @VisibleForTesting public static final String PROP_TEXT = "text"; + @VisibleForTesting public static final String PROP_PLACEHOLDER = "placeholder"; // Represents the {@code text} property only, not possible nested content. private @Nullable String mText = null; + private @Nullable String mPlaceholder = null; public ReactTextInputShadowNode() { mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? @@ -148,8 +150,9 @@ public long measure( } } - - editText.measure( + // make sure the placeholder content is also being measured + editText.setHint(getPlaceholder()); + editText.measure( MeasureUtil.getMeasureSpec(width, widthMode), MeasureUtil.getMeasureSpec(height, heightMode)); @@ -193,6 +196,16 @@ public void setText(@Nullable String text) { return mText; } + @ReactProp(name = PROP_PLACEHOLDER) + public void setPlaceholder(@Nullable String placeholder) { + mPlaceholder = placeholder; + markUpdated(); + } + + public @Nullable String getPlaceholder() { + return mPlaceholder; + } + @Override public void setTextBreakStrategy(@Nullable String textBreakStrategy) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {