react-native 监听软盘高度

import {Keyboard} from 'react-native';
     constructor(props) {
          super(props);
          this.state = {keyBoardHeight: 0}
     }

    //监听软键盘
    componentWillMount() {
        this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
        this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide.bind(this));
    }

    componentWillUnmount() {
        this.keyboardDidShowListener.remove()
        this.keyboardDidHideListener.remove()
    }

    _keyboardDidShow(e) {
        this.setState({keyBoardHeight: e.endCoordinates.height})
    }

    _keyboardDidHide() {
        this.setState({keyBoardHeight: 0})
    }

安卓手机添加在底部的文字,在软盘弹出后位置会上移导致页面样式崩掉,可以通过监听软盘高度达到底部样式的弹性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值