React Native 键盘的弹出与隐藏

1. 添加监听

componentWillMount() {
    this.keyboardWillShowSub = Keyboard.addListener('keyboardDidShow', () => this.keyboardWillShow());
    this.keyboardWillHideSub = Keyboard.addListener('keyboardDidHide', () => this.keyboardWillHide());
}

componentWillUnmount() {
    this.keyboardWillShowSub.remove();
    this.keyboardWillHideSub.remove();
}

keyboardWillHide() {
   // 做想做的事,比如解决键盘弹出遮挡input框的问题

};

keyboardWillShow() {
   //

};

2. TextInput 控件外层用 KeyboardAvoidingView 包裹

render() {
    return (
         this.setState({userName: text})}
        />
         this.setState({password: text})}
        />
         {
              
            }}>
            登录
        
    );
}

你可能感兴趣的:(React Native 键盘的弹出与隐藏)