Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable keyboard #14045

Closed
nazarTrynko opened this issue May 18, 2017 · 70 comments
Closed

Disable keyboard #14045

nazarTrynko opened this issue May 18, 2017 · 70 comments
Labels
Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Resolution: Locked This issue was locked by the bot. Type: Enhancement A new feature or enhancement of an existing feature.

Comments

@nazarTrynko
Copy link

Hi, I'm using View as a custom keyboard. Is it possible that default Keyboard is not showing when TextInput is in focus?

@st0ffern
Copy link

See docs on Keyboard and TextInput

import {Keyboard} from 'react-native'

<TextInput
  onFocus={Keyboard.dismiss()}
/>

@nazarTrynko
Copy link
Author

Unfortunately, this code also makes unfocus and Keyboard appears for 1 second, but I need TextInput to stay focused

@shergin
Copy link
Contributor

shergin commented Jun 1, 2017

Could you please provide a bit more context, what is the point to have "focused" <TextInput> without keyboard? AFAIK, it is kinda pointless at least on iOS and it can be done only we implement custom (empty) input view.

@nazarTrynko
Copy link
Author

The point is to create custom keyboard, with custom animation, which will be used to fill input, instead of default keyboard

@woowalker
Copy link

+1, need custom keyboard with TextInput, just want that keyboard never show when TextInput focus

@nazarTrynko
Copy link
Author

@woowalker
Copy link

@nazarTrynko thanks, i tried it some time ago and i find that the system keyboard still will show at the first time and then quickly hide, that appear flicker, so this lib also can't solve our problem.

@devanshsanghvi
Copy link

has anyone solved this problem, i also am facing one, if i use 'Keyboard.dismiss' i loose the focus on my text input i am using custom keyboard which itself is part of my screen so i don't want any keyboard to show up at all without loosing the focus on my text input, any solution please.

@cohendl
Copy link

cohendl commented Sep 29, 2017

Anyone solved this?? Huge problem for me as well

@croshim
Copy link

croshim commented Oct 26, 2017

+1

@gxrxrdx
Copy link

gxrxrdx commented Oct 26, 2017

I'm facing same requirement, at this point I think the best course of action is to get rid of <TextInput/> and use a custom view.

@marlti7
Copy link

marlti7 commented Nov 9, 2017

Anyone solved this?? Huge problem for me as well

@bluhar
Copy link

bluhar commented Nov 15, 2017

I'm developing react native android app on handheld mobile computer(Honeywell ScanPal), try to disable soft keyboard, modify the source code like below, then build app from react native source code.

Modify ReactAndroid\src\main\java\com\facebook\react\views\textinput\ReactEditText.java

  @Override
  public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
    // Always return true if we are already focused. This is used by android in certain places,
    // such as text selection.
    if (isFocused()) {
      return true;
    }
    if (!mIsJSSettingFocus) {
      return false;
    }
    setFocusableInTouchMode(true);
    boolean focused = super.requestFocus(direction, previouslyFocusedRect);
	// showSoftKeyboard();  Comment out this line
    return focused;
  }

Now click the TextInput, the soft keyboard will be hide, But it still show when the TextInput be clicked twice in succession, I'm not find the solution, but it's enough for me. My english is not good, hope you got it.

  • "react": "16.0.0-beta.5"
  • "react-native": "0.49.5"

Ref: https://facebook.github.io/react-native/releases/0.49/docs/android-building-from-source.html

@shergin
Copy link
Contributor

shergin commented Nov 19, 2017

So, the actual solution for all mentioned cases can be providing a way to customize/replace standard keyboard (inputView)? Right?

@ccwasden
Copy link

ccwasden commented Dec 30, 2017

@shergin In some cases the solution may be to provide a setting to have the keyboard not come up at all when the field is selected. I may not want any input view (because I want my num pad to show on the view whether or not the text field is selected - disabled if not selected)

but I think it would be a higher priority to provide a custom input view functionality because what i describe here is an edge case, and would probably be solved by a 0 height inputView

@JCMais
Copy link

JCMais commented Feb 10, 2018

a keyboardType of none would be best solution here. Currently I'm simply using a TextInput with editable={false}.

The only downside of that is that we lose the cursor.

@poicooler
Copy link

Yeah, a keyboardType={'none'} would be perfect

@react-native-bot react-native-bot added Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Feature Request 🌟 labels Mar 9, 2018
@smithaitufe
Copy link

@react-native-bot Why was this closed at all?

@AlePue
Copy link

AlePue commented Apr 11, 2018

+1

1 similar comment
@fer-ri
Copy link

fer-ri commented May 2, 2018

👍

@nitinsh99
Copy link

nitinsh99 commented May 19, 2018

This is a must requirement and a VERY valid use case. I am clicking on TextInput to transition to another screen. Something like this

Now, I need Keyboard to NOT show up when the search bar in the first screen is in focus. But as everyone over here is saying, it shows up for a split second even if you call dismiss(). Please don't ignore genuine requests..

@kashishgrover
Copy link

@nitinsh99 talking to a bot? 😛

@felipecarvalho
Copy link

felipecarvalho commented Jun 6, 2018

In my case, I solved a similar issue with this "trick":

<TextInput value={this.state.input} editable={false} onTouchStart={() => { this.setState({ input: this.state.query }); }} />

PS.: Works only on iOS

I hope that this snippet help someone.

@sneerin
Copy link

sneerin commented Jun 11, 2018

yeah, we miss the focus when disable editing, the custom keyboard makes things more complicated.

@jbcullis
Copy link

Please keep this one open, while it's an infrequent use case it's a very important one for those of us looking to optimize the users experience in data management.
To date, we've rolled our own but if we could scrap our own text field and selector in favor of a standard input that enables the magnifying glass selector and copy / paste that would be great.

@RocKhalil
Copy link

+1,
This also helps with creating a barcode text input, for example: you select the input but the keyboard doesn't show, then you scan with your barcode reader and you get your result in the field.

@wrod7
Copy link

wrod7 commented Jul 24, 2018

I need this functionality as well.

I don't know what is causing this behavior but see this gif below. One of my text boxes doesn't open the keyboard but it allows me to type.. both keyboards have the same props and styling..

anyone know what else could cause it to not bring up the keyboard?

jul-24-2018 16-10-55

@Ash-faq
Copy link

Ash-faq commented Mar 15, 2019

Dose any one found solution to disable the keyboard in ios with textInput stay focused

@itgou
Copy link

itgou commented Mar 21, 2019

In my case, I solved a similar issue with this "trick":

<TextInput value={this.state.input} editable={false} onTouchStart={() => { this.setState({ input: this.state.query }); }} />

PS.: Works only on iOS

I hope that this snippet help someone.

when I use editable={false} it won't trigger onTouchStart event, but trigger when editable={true} do you know why? by the way, where is onTouchStart event, I cannot find it in react-native document?
By the way, I cannot'

@spencore
Copy link

That's a valid issue, I want to make a datepicker that looks like my regular input and hook it up with react-native-modal-datetime-picker.

Solved it in my specific case by disabling pointer events on Input's container:

  <>
    <TouchableWithoutFeedback onPress={this.toggleVisible}>
      <View>
        <View pointerEvents="none">
          <Input
            value={String(value)}
            placeholder={placeholder}
          />
        </View>
      </View>
    </TouchableWithoutFeedback>
    <DateTimePicker
      isVisible={this.state.visible}
      onConfirm={onChange}
      onCancel={this.toggleVisible}
    />
  </>

Thank you @jacek213 !!! Exactly what I needed. I'm doing the same thing with native-modal-datetime-picker

@josephmbeveridge
Copy link

@hramos Can you please re-open this issue? It looks pretty clear from the number of requests that this is still a valid concern without a proper solution for both platforms. Many large scale apps implement custom keyboards and the provided suggestions are not adequate for a good UX.

@robin1990
Copy link

keyboardType={'none'} would be really nice.

@Mattimus333
Copy link

Mattimus333 commented Apr 25, 2019

That's a valid issue, I want to make a datepicker that looks like my regular input and hook it up with react-native-modal-datetime-picker.

Solved it in my specific case by disabling pointer events on Input's container:

  <>
    <TouchableWithoutFeedback onPress={this.toggleVisible}>
      <View>
        <View pointerEvents="none">
          <Input
            value={String(value)}
            placeholder={placeholder}
          />
        </View>
      </View>
    </TouchableWithoutFeedback>
    <DateTimePicker
      isVisible={this.state.visible}
      onConfirm={onChange}
      onCancel={this.toggleVisible}
    />
  </>

@jacek213 Thanks! This gets the job done!

@Grohden
Copy link

Grohden commented May 9, 2019

@jacek213 this disables the TextInput scroll :/

edit: maybe a focusable={false} could be usefull?

@tanf1995
Copy link

come on!anyone has solution?

@RocKhalil
Copy link

@Grohden @tanf1995 I wrote a monkey patch for Android here. If this works for you, try replicating it on iOS.

@JackClown
Copy link

+1

@piotrpazola
Copy link

We should create a Native Module that calls InputMethodManager to close the keyboard when visible and add an onFocus function on our TextInput that calls the Native's keyboard dismissal function.

Thank you @RocKhalil! You've saved my day...

Best regards

@riso
Copy link

riso commented May 24, 2019

I opened #25028 which allows to overcome this limitation properly - i.e. without having to hide the native keyboard when it appears.

Is any react-native contributor able to review it?

facebook-github-bot pushed a commit that referenced this issue May 24, 2019
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes #14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: #25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
josephmbeveridge pushed a commit to josephmbeveridge/react-native that referenced this issue Jun 5, 2019
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes facebook#14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: facebook#25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
josephmbeveridge pushed a commit to josephmbeveridge/react-native that referenced this issue Jun 6, 2019
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes facebook#14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: facebook#25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
@hotaryuzaki
Copy link

That's a valid issue, I want to make a datepicker that looks like my regular input and hook it up with react-native-modal-datetime-picker.

Solved it in my specific case by disabling pointer events on Input's container:

  <>
    <TouchableWithoutFeedback onPress={this.toggleVisible}>
      <View>
        <View pointerEvents="none">
          <Input
            value={String(value)}
            placeholder={placeholder}
          />
        </View>
      </View>
    </TouchableWithoutFeedback>
    <DateTimePicker
      isVisible={this.state.visible}
      onConfirm={onChange}
      onCancel={this.toggleVisible}
    />
  </>

wooooooooow...
nice trick, it works like a charm

@ThaJay
Copy link

ThaJay commented Jul 18, 2019

I'm developing react native android app on handheld mobile computer(Honeywell ScanPal), try to disable soft keyboard, modify the source code like below, then build app from react native source code.

+1,
This also helps with creating a barcode text input, for example: you select the input but the keyboard doesn't show, then you scan with your barcode reader and you get your result in the field.

This is also necessary for some devices with physical keyboard, keep focus but not show keyboard software.

I need that too, I am using an external keyboard(a bluetooth barcode scanner to be exact) for a specific usecase, and I do not want that soft keyboard keeps appearing onFocus, and I do not want to close soft keyboard from android settings because I have login screen etc. Still looking for a simple hack.

I am also working with a barcode scanner that acts like a keyboard.

I opened #25028 which allows to overcome this limitation properly - i.e. without having to hide the native keyboard when it appears.

Is any react-native contributor able to review it?

Thank you @riso !
I see your request has been merged. Will keep an eye on when it makes it into a release. If it takes too long I will have to mess around with forking the repo.

edit: It seems the modules I am using are not ready for 0.60 yet so it's a shame this commit got delayed until after 0.59

grabbou pushed a commit that referenced this issue Aug 7, 2019
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes #14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: #25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
@ckOfor
Copy link

ckOfor commented Aug 8, 2019

This hasn't been solved because showSoftInputOnFocus prop does nothing

@Runtime007
Copy link

@swaroopa94 check this comment where we already know that this is happening; the onFocus only fires the first time you press the keyboard, however, if you press it another time, it won't fire it. The keyboard is appearing due to the no-firing event.

I changed the method

@ReactMethod
    public void hideKeyboard() {
        final Activity activity = getCurrentActivity();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

            }
        });
    }

the keyboard will not show any more. just call getWindow().clearFlags() if you want to show it again.

@poonamdhomane
Copy link

is there any solution for iOS .. it is working but still for few seconds keyboard is appearing which looks irritating

@OnurErtugral
Copy link

keyboardType= "none" option would be a great solution.

@facebook facebook locked as resolved and limited conversation to collaborators Dec 11, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 11, 2019
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this issue Mar 10, 2020
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes facebook#14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: facebook#25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Resolution: Locked This issue was locked by the bot. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.