Fix copy paste second attempt

Reviewed By: AaaChiuuu

Differential Revision: D5080735

fbshipit-source-id: c76fb204c114b8a8fc884aa208ad5fa9bba01fcb
This commit is contained in:
Andrew Y. Chen 2017-05-18 09:42:49 -07:00 committed by Facebook Github Bot
parent 93a1d592d6
commit 6c4e8d74cd
1 changed files with 15 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
@ -91,13 +92,26 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
@Override
public ReactEditText createViewInstance(ThemedReactContext context) {
ReactEditText editText = new ReactEditText(context);
final ReactEditText editText = new ReactEditText(context);
int inputType = editText.getInputType();
editText.setInputType(inputType & (~InputType.TYPE_TEXT_FLAG_MULTI_LINE));
editText.setReturnKeyType("done");
editText.setTextSize(
TypedValue.COMPLEX_UNIT_PX,
(int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP)));
// Fixes an issue where the EditText is not selectable if nested within a
// ViewPagerAndroid on some versions of Android (API 16, 23)
editText.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
editText.getViewTreeObserver().removeOnPreDrawListener(this);
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
editText.setTextIsSelectable(true);
editText.setSelection(selectionStart, selectionEnd);
return true;
}
});
return editText;
}