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