autofocus input react native code example

Example: react native autofocus on text input with keyboard display

const [isFocused, setIsFocued] = React.useState(true)

  const setFocus = React.useCallback(() => {
    setIsFocued(true)
  }, [])

  const setBlur = React.useCallback(() => {
    setIsFocued(false)
  }, [])

  const navi = useNavigation()

  React.useEffect(() => {
    navi.addListener('focus', setFocus)
    navi.addListener('blur', setBlur)
    return () => {
      navi.removeListener('focus', setFocus)
      navi.removeListener('blur', setBlur)
    }
  }, [])

  return (
    <View>
        {focused && <TextInput autoFocus />}
    </View>
  )