diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index b354d8418d452b..bfde62b5d13896 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -304,6 +304,15 @@ const TextInput = React.createClass({ * @platform android */ numberOfLines: PropTypes.number, + /** + * When `false`, if there is a small amount of space available around a text input + * (e.g. landscape orientation on a phone), the OS may choose to have the user edit + * the text inside of a full screen text input mode. When `true`, this feature is + * disabled and users will always edit the text directly inside of the text input. + * Defaults to `false`. + * @platform android + */ + disableFullscreenUI: PropTypes.bool, /** * If `true`, the keyboard disables the return key when there is no text and * automatically enables it when there is text. The default value is `false`. @@ -708,6 +717,7 @@ const TextInput = React.createClass({ onTextInput={this._onTextInput} text={this._getText()} children={children} + disableFullscreenUI={this.props.disableFullscreenUI} />; return ( diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 9529a3e327912b..90af968f044330 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -33,6 +33,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -74,6 +75,8 @@ public class ReactEditText extends EditText { private int mStagedInputType; private boolean mContainsImages; private boolean mBlurOnSubmit; + private boolean mDisableFullscreen; + private @Nullable String mReturnKeyType; private @Nullable SelectionWatcher mSelectionWatcher; private @Nullable ContentSizeWatcher mContentSizeWatcher; private final InternalKeyListener mKeyListener; @@ -97,6 +100,7 @@ public ReactEditText(Context context) { mIsSettingTextFromJS = false; mIsJSSettingFocus = false; mBlurOnSubmit = true; + mDisableFullscreen = false; mListeners = null; mTextWatcherDelegator = null; mStagedInputType = getInputType(); @@ -254,6 +258,24 @@ public boolean getBlurOnSubmit() { return mBlurOnSubmit; } + public void setDisableFullscreenUI(boolean disableFullscreenUI) { + mDisableFullscreen = disableFullscreenUI; + updateImeOptions(); + } + + public boolean getDisableFullscreenUI() { + return mDisableFullscreen; + } + + public void setReturnKeyType(String returnKeyType) { + mReturnKeyType = returnKeyType; + updateImeOptions(); + } + + public String getReturnKeyType() { + return mReturnKeyType; + } + /*protected*/ int getStagedInputType() { return mStagedInputType; } @@ -407,6 +429,42 @@ private boolean isMultiline() { setGravity((getGravity() & ~Gravity.VERTICAL_GRAVITY_MASK) | gravityVertical); } + private void updateImeOptions() { + // Default to IME_ACTION_DONE + int returnKeyFlag = EditorInfo.IME_ACTION_DONE; + if (mReturnKeyType != null) { + switch (mReturnKeyType) { + case "go": + returnKeyFlag = EditorInfo.IME_ACTION_GO; + break; + case "next": + returnKeyFlag = EditorInfo.IME_ACTION_NEXT; + break; + case "none": + returnKeyFlag = EditorInfo.IME_ACTION_NONE; + break; + case "previous": + returnKeyFlag = EditorInfo.IME_ACTION_PREVIOUS; + break; + case "search": + returnKeyFlag = EditorInfo.IME_ACTION_SEARCH; + break; + case "send": + returnKeyFlag = EditorInfo.IME_ACTION_SEND; + break; + case "done": + returnKeyFlag = EditorInfo.IME_ACTION_DONE; + break; + } + } + + if (mDisableFullscreen) { + setImeOptions(returnKeyFlag | EditorInfo.IME_FLAG_NO_FULLSCREEN); + } else { + setImeOptions(returnKeyFlag); + } + } + @Override protected boolean verifyDrawable(Drawable drawable) { if (mContainsImages && getText() instanceof Spanned) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 50d20631b43182..9ccf3ab811224c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -88,7 +88,7 @@ public ReactEditText createViewInstance(ThemedReactContext context) { ReactEditText editText = new ReactEditText(context); int inputType = editText.getInputType(); editText.setInputType(inputType & (~InputType.TYPE_TEXT_FLAG_MULTI_LINE)); - editText.setImeOptions(EditorInfo.IME_ACTION_DONE); + editText.setReturnKeyType("done"); editText.setTextSize( TypedValue.COMPLEX_UNIT_PX, (int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP))); @@ -475,29 +475,12 @@ public void setKeyboardType(ReactEditText view, @Nullable String keyboardType) { @ReactProp(name = "returnKeyType") public void setReturnKeyType(ReactEditText view, String returnKeyType) { - switch (returnKeyType) { - case "done": - view.setImeOptions(EditorInfo.IME_ACTION_DONE); - break; - case "go": - view.setImeOptions(EditorInfo.IME_ACTION_GO); - break; - case "next": - view.setImeOptions(EditorInfo.IME_ACTION_NEXT); - break; - case "none": - view.setImeOptions(EditorInfo.IME_ACTION_NONE); - break; - case "previous": - view.setImeOptions(EditorInfo.IME_ACTION_PREVIOUS); - break; - case "search": - view.setImeOptions(EditorInfo.IME_ACTION_SEARCH); - break; - case "send": - view.setImeOptions(EditorInfo.IME_ACTION_SEND); - break; - } + view.setReturnKeyType(returnKeyType); + } + + @ReactProp(name = "disableFullscreenUI", defaultBoolean = false) + public void setDisableFullscreenUI(ReactEditText view, boolean disableFullscreenUI) { + view.setDisableFullscreenUI(disableFullscreenUI); } private static final int IME_ACTION_ID = 0x670;