textInput: Fix placeholder is not completely visible on Android. (#20337)

Summary:
On Android, placeholder of TextInput is not completely visible.
TextInput had some default fixed width. On iOS it is perfectly
visible.

This commit makes it consistent on both the platforms.

Before:
https://user-images.githubusercontent.com/39303760/43045649-54cb45e8-8dda-11e8-9935-059ad8ee9def.png

After:
https://user-images.githubusercontent.com/39303760/43045650-54fb9428-8dda-11e8-88b8-176839d6c0a7.png

Testing code:
a0a6fbb491/App.js

Clone code from a0a6fbb491/App.js and test on Android with and without this commit.

Before:
https://user-images.githubusercontent.com/39303760/43045649-54cb45e8-8dda-11e8-9935-059ad8ee9def.png

After:
https://user-images.githubusercontent.com/39303760/43045650-54fb9428-8dda-11e8-88b8-176839d6c0a7.png

 [ANDROID] [BUGFIX] [TextInput] - Fix placeholder is not completely visible on Android.
Pull Request resolved: https://github.com/facebook/react-native/pull/20337

Differential Revision: D8950051

Pulled By: mdvacca

fbshipit-source-id: a583a48c90ecd55d8dd8c6f4eef829608b2a6079
This commit is contained in:
Vishwesh Jainkuniya 2018-07-22 23:11:55 -07:00 committed by Facebook Github Bot
parent e592d6f8c7
commit 84022321c4
1 changed files with 4 additions and 1 deletions

View File

@ -21,11 +21,13 @@ public final class ReactTextInputLocalData {
private final int mMaxLines; private final int mMaxLines;
private final int mInputType; private final int mInputType;
private final int mBreakStrategy; private final int mBreakStrategy;
private final CharSequence mPlaceholder;
public ReactTextInputLocalData(EditText editText) { public ReactTextInputLocalData(EditText editText) {
mText = new SpannableStringBuilder(editText.getText()); mText = new SpannableStringBuilder(editText.getText());
mTextSize = editText.getTextSize(); mTextSize = editText.getTextSize();
mInputType = editText.getInputType(); mInputType = editText.getInputType();
mPlaceholder = editText.getHint();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mMinLines = editText.getMinLines(); mMinLines = editText.getMinLines();
@ -48,8 +50,9 @@ public final class ReactTextInputLocalData {
editText.setMinLines(mMinLines); editText.setMinLines(mMinLines);
editText.setMaxLines(mMaxLines); editText.setMaxLines(mMaxLines);
editText.setInputType(mInputType); editText.setInputType(mInputType);
editText.setHint(mPlaceholder);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
editText.setBreakStrategy(mBreakStrategy); editText.setBreakStrategy(mBreakStrategy);
} }
} }
} }