How to open keyboard automatically in React Native?

后端 未结 4 1393
时光取名叫无心
时光取名叫无心 2020-12-17 10:51

I have a screen in my React Native application in which I have few text fields.

I was wondering if there is any way in which on screen load my keyword opens automati

4条回答
  •  天命终不由人
    2020-12-17 11:08

    My way (there was a problem with focusing and showing a keyboard on component render)

    import { InteractionManager, TextInput } from 'react-native';
    
    ...
    
    inputRef = React.createRef();
    
    componentDidMount() {
      this.focusInputWithKeyboard()
    }
    
    focusInputWithKeyboard() {
      InteractionManager.runAfterInteractions(() => {
        this.inputRef.current.focus()
      });
    }
    
    render() {
      
    }
    

提交回复
热议问题