Answers for "react native autofocus on text input with keyboard display"

0

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>
  )
Posted by: Guest on December-13-2020

Code answers related to "react native autofocus on text input with keyboard display"

Code answers related to "Javascript"

Browse Popular Code Answers by Language