Skip to content

Commit 86f24cc

Browse files
Jiaqi Wufacebook-github-bot
Jiaqi Wu
authored andcommitted
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
1 parent de57327 commit 86f24cc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
4141
private @Nullable ReactTextInputLocalData mLocalData;
4242

4343
@VisibleForTesting public static final String PROP_TEXT = "text";
44+
@VisibleForTesting public static final String PROP_PLACEHOLDER = "placeholder";
4445

4546
// Represents the {@code text} property only, not possible nested content.
4647
private @Nullable String mText = null;
48+
private @Nullable String mPlaceholder = null;
4749

4850
public ReactTextInputShadowNode() {
4951
mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ?
@@ -148,8 +150,9 @@ public long measure(
148150
}
149151
}
150152

151-
152-
editText.measure(
153+
// make sure the placeholder content is also being measured
154+
editText.setHint(getPlaceholder());
155+
editText.measure(
153156
MeasureUtil.getMeasureSpec(width, widthMode),
154157
MeasureUtil.getMeasureSpec(height, heightMode));
155158

@@ -193,6 +196,16 @@ public void setText(@Nullable String text) {
193196
return mText;
194197
}
195198

199+
@ReactProp(name = PROP_PLACEHOLDER)
200+
public void setPlaceholder(@Nullable String placeholder) {
201+
mPlaceholder = placeholder;
202+
markUpdated();
203+
}
204+
205+
public @Nullable String getPlaceholder() {
206+
return mPlaceholder;
207+
}
208+
196209
@Override
197210
public void setTextBreakStrategy(@Nullable String textBreakStrategy) {
198211
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {

0 commit comments

Comments
 (0)