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
Focusing on a text input when navigating to a new screen only works when adding to the stack, not when going back. #8564
Comments
The versions mentioned in the issue for the following packages differ from the latest versions on npm:
Can you verify that the issue still exists after upgrading to the latest versions of these packages? |
I updated my packages and tried again (updated my report with my current packages). The issue persists. |
I have the same problem. Navigating back in the stack does not autoFocus the textinput if the autoFocus prop is true. It also does not work if you try to call focus() method directly on the textInput ref. I have found that adding a timeout before focusing the text input does work, but this is a workaround. Here is the reproduction repo https://github.com/KristineTrona/rn-autofocus-issue/tree/master - see the readme, I found what is causing the issue, but it still seems a buggy behaviour to me. |
this same issue also affects hasTVPreferredFocus new screens with hasTVPreferredFocus true will get focus but if you go back to the screen before the hasTVPreferredFocus on that screen is not focused again instead it goes to the very first touchable |
That's because the
And going back to a screen doesn't remount it. The screen stays mounted behind all the time. Just passing by this issue |
@yairopro That could be understandable if it would simply not focus the input - but it does focus it for a second then unfocuses it. This quote from the bug description won't work either:
|
My bad |
@Rob2k9 I also have the same problem. Is there a solution? |
Same problem here.. autoFocus on TextInput didn't work. Edit (workaround ):
|
Haven't tried this myself yet, but does using the useFocusEffect work?
|
This unfortunately didn't work for me, still no auto focus. The code I used was:
I'm using
EDIT: Due to time constraints I ended up using this feel-dirty-work-around:
|
For me, it only works on a hard screen refresh but not on going back. The only workaround that really works in my code is @badiozam feel-dirty solution 😬 |
Same problem, only solved with the timer workaround |
I used the following code on the button: const onMouseDown = (event) => { |
Current Behavior
Calling
.focus()
on a text input (or using autoFocus) when the screen becomes focused works when you add a screen to the stack (Screen A -> Screen B) but not when going back (Screen B -> Screen A).Instead, the input is focused for a second then blurs immediately.
Expected Behavior
The input should stay focused
How to reproduce
Your Environment
The text was updated successfully, but these errors were encountered: