How to open keyboard automatically in React Native?

后端 未结 4 1370
时光取名叫无心
时光取名叫无心 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 10:54

    The selected solution did not work for me due to stack navigation (see comment of "SoundStage" on selected solution)

    I added a new variable openTheKeyboard to the state initially set to false.

    My hacky solution:

    componentDidMount() {
      this.setState({ openTheKeyboard: true });
    }
    
    componentDidUpdate() {
      if (this.state.openTheKeyboard) {
        this.textInput.focus();
        this.setState({ openTheKeyboard: false });
      }
    }
    

提交回复
热议问题