react native获取键盘高度

Posted 我的大刀早已饥渴难耐

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react native获取键盘高度相关的知识,希望对你有一定的参考价值。

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

componentWillMount() {
this.keyboardDidShowListener = Keyboard.addListener(‘keyboardDidShow‘, this._keyboardDidShow.bind(this));
this.keyboardDidHideListener = Keyboard.addListener(‘keyboardDidHide‘, this._keyboardDidHide.bind(this));
}

_keyboardDidShow(e) {
async function run(self) {
await self.setState({
keyboardHeight: e.endCoordinates.height
});
self.refs.scroll.scrollTo({
x: 0, y: self.state.keyboardHeight, animated: true
})
}

run(this);
}

_keyboardDidHide(e) {
this.setState({
keyboardHeight: 0
})
}

以上是关于react native获取键盘高度的主要内容,如果未能解决你的问题,请参考以下文章