美文网首页React Native学习
React Native 点击软键盘消失按钮后,点击按钮需要点击

React Native 点击软键盘消失按钮后,点击按钮需要点击

作者: 雨飞飞雨 | 来源:发表于2017-09-11 17:26 被阅读100次

    经过试验发现点击软键盘消失按钮后,或者点击屏幕其他的地方,软键盘消失,点击按钮却需要两次的原因是,焦点还在原来的TextInput上面。

    解决的办法就是,监听软键盘的消失方法,然后在消失方法里面,再一次调用软键盘消失方法:

    import { Keyboard, TextInput } from 'react-native'; 
    componentWillMount () {
            this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
            this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
    }
    componentWillUnmount() {
            this.keyboardDidShowListener.remove();
            this.keyboardDidHideListener.remove();
    }
    _keyboardDidShow () {
    
    }
    _keyboardDidHide () {
             dismissKeyboard();
    }
    

    参考文章:
    键盘遮挡问题处理;
    ReactNative之键盘Keyboard的弹出与消失示例;

    相关文章

      网友评论

      • 骐_4082:请问dismissKeyboard()方法是怎么定义的,我这边会报错Can`t find variable: dismissKeyboard
        雨飞飞雨:const dismissKeyboard = require('dismissKeyboard');

      本文标题:React Native 点击软键盘消失按钮后,点击按钮需要点击

      本文链接:https://www.haomeiwen.com/subject/ckpfsxtx.html