How to open keyboard automatically in React Native?

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

    This seems to be working in my simulator. Have not confirmed on a real device.

    constructor(props) {
      super(props);
      this.buildNameTextInput = React.createRef();
    }
    
     {
        this.buildNameTextInput = true
        this.props.setSaveBuildModal(true)
      }}
    >
       Save Build 
    
    
     this.props.setCurrentBuildName(buildName)}
      value={this.props.buildName}
    />
    
    1. I needed the constructor to register the reference
    2. The handler sets a local variable to true
    3. autoFocus will trigger the field to be focused. The keyboard sometimes opens up on android simulator (this I cannot explain).
    4. ref is for the reference to the DOM element

提交回复
热议问题