如何在键盘出现之前采取行动?
How to take an action before keyboard shows up?
我为我的键盘添加了一个监听器,这样我就可以在它出现时做一些事情,
首先我尝试了 keyboardDidShow
并且成功了,但是我希望我的函数在键盘出现之前被触发,所以根据 react native doc 我将它更改为 keyboardWillShow
。现在完全没用了!
componentDidMount() {
this.keyboardWillShowListener = Keyboard.addListener(
'keyboardWillShow',
()=> this.setState({keyboard_open: true})
);
}
我是不是漏掉了什么?
您的代码没问题。正如您在文档中看到的那样,
keyboardWillShow
as well as keyboardWillHide
are generally not
available on Android since there is no native corresponding event.
因此,如果您在 Android 设备上进行测试,它不受支持,但它应该可以在 iOS 设备上正常工作。
我为我的键盘添加了一个监听器,这样我就可以在它出现时做一些事情,
首先我尝试了 keyboardDidShow
并且成功了,但是我希望我的函数在键盘出现之前被触发,所以根据 react native doc 我将它更改为 keyboardWillShow
。现在完全没用了!
componentDidMount() {
this.keyboardWillShowListener = Keyboard.addListener(
'keyboardWillShow',
()=> this.setState({keyboard_open: true})
);
}
我是不是漏掉了什么?
您的代码没问题。正如您在文档中看到的那样,
keyboardWillShow
as well askeyboardWillHide
are generally not available on Android since there is no native corresponding event.
因此,如果您在 Android 设备上进行测试,它不受支持,但它应该可以在 iOS 设备上正常工作。