【问题标题】:Figure out if TextInput has focus via ref确定 TextInput 是否通过 ref 获得焦点
【发布时间】:2020-08-09 15:06:35
【问题描述】:

配置如下:

class MyComponent extends Component {
    constructor(props) {
        super(props);
     
        this.inputRef = React.createRef();
    }

    ...
 
    render() {
        ...
        <TextInput style={styles.textInput}
           ...                           
           ref={this.inputRef}
        />
        ...
    }
}

问。如何在 render() 方法中找出 TextInput 是否有焦点

【问题讨论】:

    标签: react-native react-native-textinput


    【解决方案1】:

    您可以使用 this functions 或通过在 textInput 中注册 onBlur() 和 onFocus() 回调函数来创建自定义设置来检查。

    例如

    <TextInput
              onFocus={() =>console.log("focus received" ) }
              onBlur={() => console.log("focus lost") } />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-26
      • 2020-09-07
      • 1970-01-01
      • 2015-03-29
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多