Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 通过ref确定TextInput是否具有焦点_React Native_React Native Textinput - Fatal编程技术网

React native 通过ref确定TextInput是否具有焦点

React native 通过ref确定TextInput是否具有焦点,react-native,react-native-textinput,React Native,React Native Textinput,配置如下: class MyComponent extends Component { constructor(props) { super(props); this.inputRef = React.createRef(); } ... render() { ... <TextInput style={styles.textInput} ...

配置如下:

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

    ...
 
    render() {
        ...
        <TextInput style={styles.textInput}
           ...                           
           ref={this.inputRef}
        />
        ...
    }
}
类MyComponent扩展组件{
建造师(道具){
超级(道具);
this.inputRef=React.createRef();
}
...
render(){
...
...
}
}

Q.如何确定TextInput在render()方法中是否具有焦点?

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

e、 g

console.log(“接收到焦点”)}
onBlur={()=>console.log(“焦点丢失”)}/>
<TextInput
          onFocus={() =>console.log("focus received" ) }
          onBlur={() => console.log("focus lost") } />