react-native-screens: Keyboard doesn't show up when autoFocus on component mount
Hello,
I am trying to use react-native-screens combine with react-navigation for my app for better performance, however I have a weird problem. Indeed, when I have a new page mounting with a TextInput
set on autoFocus
, it focused as expected but the keyboard does not show up on the screen.
If I don’t put useScreens()
it works perfectly, the TextInput is focused and the Keyboard appears.
react-native: 0.59.1; react-navigation: 3.8.1; react-native-screens: 1.0.0-alpha.22; OS: Android; Device: Real;
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 22
- Comments: 43 (9 by maintainers)
Same problem here.
I’m using a settimeout in componentdidmount to trigger the focus after some milliseconds, but still not the best because there is a necessary delay.
setTimeout(() => this.ref.focus(), 150)
Remove autoFocus prop on the component or else it won’t work.Looking forward to a better solution if possible.
Any updates for this problem? I have this problem in Android.
I have tried to use autoFocus and ref, but it didn’t help. What workarounds did you use?
Here it’s working with InteractionManager:
Had the same issue. react-native-screens upgrading didn’t help.
Solved it by removing autoFocus={true} and setting timeout. I have a popup as a functional component and using “current.focus()” with Refs like this:
400ms only working for me
Platform.OS === “ios” ? this.ref.focus() : setTimeout(() => this.ref.focus(), 400)
For anyone looking for some typescript implementation
I personally am still seeing this issue with 2.0.0-alpha.17 && react-navigation: 4.0.10 on Android devices.
For anyone stumbling on this issue. Here is a reusable TS hook using clind-arthur’s example:
I was able to get this to work using a shortened timer (50ms), thank you to the workaround above.
Bump?
This issue is pretty significant for user experience. I may take care of it later this year if it’s not fixed by then.
make sure in android you removed autofocus
This works. Why is this issue closed? It’s definitely a significant bug that’s still around.
I solved the problem by showing
TextInput
only in focused screen. In other words, re-showingTextInput
fires auto focus again.react-navigation NavigationEvents component seems to also work using the onDidFocus prop, but it feels slower than using the setTimout like above.
Closing since it should be fixed by #1214.
Also had this problem. I used this and also documentation from here: https://reactnavigation.org/docs/function-after-focusing-screen/
@ferrannp I had the same problem and can confirm that
2.0.0-alpha.3
fixes this issue.Can you try
2.0.0-alpha3
? This https://github.com/kmagiera/react-native-screens/pull/152/files should solve the issue.Me too ^^^
any workarounds for this?
My idea is that because it’s creating a new native view it just doesn’t propagate focus event properly on Android. Haven’t researched it properly yet, though.
Yea, it seems this project has quite a few issues compared to plain View-based screens that need to resolved. Everything is more complicated in Native code than in JS.