点击输入框外部, 失去焦点并收起键盘

点击输入框外部, 失去焦点并收起键盘

class SignInScreen extends React.Component {
  constructor(props) {
    super(props);

    this.textInputPhoneNo = React.createRef();
    this.rootClick = this.rootClick.bind(this);
  }

  render() {
    return (
      
          
            
    ...
rootClick() {
  this.textInputPhoneNo.current.blur();
}

1. constructor()

this.textInputPhoneNo = React.createRef();
this.rootClick = this.rootClick.bind(this);

这个是解决 TouchableHighlight 点击后会有一个背景的变化, 所以, 这里设置一个背景和当前页面一样, 更友好

2.

onPressIn={this.rootClick}>

3.

ref={this.textInputPhoneNo}

4.

rootClick() {
  this.textInputPhoneNo.current.blur();
}

你可能感兴趣的:(React)