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

Android: Calling TextInput instance's focus() after keyboard is closed via back button/submit doesn't bring up keyboard #19366

Closed
3 tasks done
narobertson42 opened this issue May 21, 2018 · 6 comments
Labels
Component: TextInput Related to the TextInput component. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@narobertson42
Copy link

narobertson42 commented May 21, 2018

Issue was closed and not fixed #11979

Environment

Environment:
OS: macOS High Sierra 10.13.4
Node: 9.9.0
Yarn: 1.6.0
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3.1 Build version 9E501
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.3.2 => 16.3.2
react-native: 0.55.4 => 0.55.4

Steps to Reproduce

Calling focus() on a TextInput instance after keyboard is closed via Android back or submit/enter soft key doesn't bring keyboard back up.

Obviously, you can just tap on the TextInput itself to bring the keyboard back up, but the expected behaviour of calling focus() should still apply. The problem is a pain when the TextInput is hidden and their is a different representation of the TextInput's state, such as a custom pin code entry form.

Reproduction
<TouchableOpacity onPress={() => this.textInput.focus()}>
Focus

<TextInput ref={(component) => this.textInput = component}/>

Expected Behavior

Tap TouchableOpacity to focus. Press back to dismiss keyboard. Tap TouchableOpacity. Keyboard opens

Actual Behavior

Tap TouchableOpacity to focus. Press back to dismiss keyboard. Tap TouchableOpacity. Keyboard doesn't open

@react-native-bot react-native-bot added 📋No Environment Info Platform: Android Android applications. Component: TextInput Related to the TextInput component. labels May 21, 2018
@anhtukhtn
Copy link

anhtukhtn commented May 22, 2018

Do you solve the problem?
I work around by:

      this.textInput.blur();

      setTimeout(() => {
        this.textInput.focus();
      }, 100);

@narobertson42
Copy link
Author

@anhtukhtn that approach works sporadically, perhaps every tenth time. My workaround was to put my hidden TextInput behind my custom TextInputDisplay and allow clicks to pass through to the TextInput. It's not a great solution, but it works for my specific use case.

@react-native-bot
Copy link
Collaborator

Please run react-native info and update your issue.

@narobertson42 narobertson42 changed the title Android: Calling TextInput instance's focus() after keyboard is closed via back button/submit doesn't bring up keyboard Android: Calling TextInput instance's focus() after keyboard is closed via back button/submit doesn't bring up keyboard May 29, 2018
@climam
Copy link

climam commented Jun 27, 2018

I also face this issue. It seems to happen only when there is a change of type of keyboard between two TextInput. @anhtukhtn, your approach always work for me. The only thing that must be done if you want the autofocus, is to implement this in your componentDidMount:

componentDidMount() {
      setTimeout(() => {
        this.workaroundFocus();
      }, 100);
}

workaroundFocus() {
      this.textInput.blur();

      setTimeout(() => {
        this.textInput.focus();
      }, 100);
}

render() {
return <TouchableOpacity onPress={() => this.workaroundFocus()}>;
}

This is pretty ugly but it does the job.

@stale
Copy link

stale bot commented Dec 21, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 21, 2018
@stale
Copy link

stale bot commented Dec 28, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Dec 28, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TextInput Related to the TextInput component. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants