简体   繁体   English

当Android Textinput autoFocus为true时,不会弹出本机键盘

[英]react native keyboard does not pop up when the Android Textinput autoFocus is true

When entering the screen the keyboard should open automatically, the problem only happens on Android.进入屏幕时,键盘应自动打开,此问题仅发生在 Android 上。

Is there another solution to open the keyboard automatically?是否有另一种自动打开键盘的解决方案?

react-native: 0.64.2反应原生:0.64.2

You can use a useRef hook to do this.您可以使用useRef挂钩来执行此操作。 Live example ( https://snack.expo.dev/@heytony01/smiling-candy ).现场示例( https://snack.expo.dev/@heytony01/smiling-candy )。

export default function App() {
  const textInputRef = React.useRef();

  // Focuses on keyboard once screen starts 
  React.useEffect(()=>{
    textInputRef.current.focus(); // opens keyboard
  },[])

  return (
    <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
        <TextInput ref={textInputRef} placeholder="Type here" style={{backgroundColor:"lightgray"}}/>
    </View>
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM