Skip to content

Commit

Permalink
Fix placeholder clipping issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jiaqi Wu authored and facebook-github-bot committed Jul 20, 2018
1 parent de57327 commit 86f24cc
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 86f24cc

Please sign in to comment.