React-native-screens: Keyboard doesn't show up when use someRef.current.focus()

Created on 20 Apr 2020  路  14Comments  路  Source: software-mansion/react-native-screens

Hey!
When use

someRef.current.focus()

nothing happends
but if use

setTimeout(() => someRef.current.focus(), 0)

I don't think that this a good idea
It is a bug?

{
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.9",
    "@react-navigation/native": "^5.1.5",
    "@react-navigation/stack": "^5.2.10",
    "@types/react-navigation": "^3.4.0",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-screens": "^2.4.0",
  },
}

Android bug native-stack

Most helpful comment

This should be fixed in react-native 0.63 (currently in RC). See https://github.com/facebook/react-native/commit/6adba409e6256fd2dcc27a4272edcedae89927af, https://github.com/facebook/react-native/commit/055a41b081c5bc9535b071d9b4b7488b92e71803

Edit: In this case you'd need to use the autoFocus prop on TextInput instead of focusing from JS with a ref.

All 14 comments

Can you create a snack that will show the issue? And what Platform does the bug occur on?

Hey!

Can you create a snack that will show the issue?

A little bit later, sorry, very busy

And what Platform does the bug occur on?

Android...

This is true, when you try to focus on component mount. It also does not work for me without timeout. But for me .current.focus doesn't work anyway, I need to run it like this:

input.current?._root?.focus?.();
or more readable:
textInput.current._root.focus();

This should be fixed in react-native 0.63 (currently in RC). See https://github.com/facebook/react-native/commit/6adba409e6256fd2dcc27a4272edcedae89927af, https://github.com/facebook/react-native/commit/055a41b081c5bc9535b071d9b4b7488b92e71803

Edit: In this case you'd need to use the autoFocus prop on TextInput instead of focusing from JS with a ref.

So RN 0.63 is finally here and the problem persists. Any solution that doesn't require to work it around with timeouts?

Did you check on RN 0.63.2?

@WoLewicki yes, that's exactly the one we're using

cc @janicduplessis

@ammichael can you be more specific on what exactly does not work and could you provide a repo with an easy reproduction of the issue?

I am closing it due to no response in more than 30 days. Feel free to comment to reopen it.

I have this did anyone of you solve it?

was anyone able to solve this problem? It was working on react native 0.59, but I upgraded to 0.63 and is not working anymore

@reyanshmishra @joaocosta9 can you provide a reproduction of this issue in TestExample project?

Also noticing the same issue with RN 0.64.1.

The above hack setTimeout(() => someRef.current.focus(), 0) seems to work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pvinis picture pvinis  路  5Comments

chengsokdara picture chengsokdara  路  3Comments

dotconnor picture dotconnor  路  5Comments

hadnet picture hadnet  路  4Comments

joshua-augustinus picture joshua-augustinus  路  4Comments