Keyboard
Keyboard模块用来控制键盘相关的事件。
用法示例
Keyboard模块可以监听原生键盘事件以做出相应回应,比如收回键盘。
- 函数式组件
- Class 组件
文档
方法
addListener()
jsx
static addListener(eventName, callback)
addListener用于注册一个 JavaScript 函数来监听处理原生键盘通知事件。
此方法会返回监听函数的引用。
参数:
| 名称 | 类型 | Required | 说明 |
|---|---|---|---|
| eventName | string | Yes | nativeEvent参数用来指明要监听的事件,具体有以下几种: |
| callback | function | Yes | 事件触发时调用的 js 函数 |
nativeEvent
This can be any of the following
keyboardWillShowkeyboardDidShowkeyboardWillHidekeyboardDidHidekeyboardWillChangeFramekeyboardDidChangeFrame
keyboardWillShow as well as keyboardWillHide are generally not available on Android since there is no native corresponding event.
注意在 Android 上只有
keyboardDidShow和keyboardDidHide事件有效。如果 Android 版本小于等于 10, 且android:windowSoftInputMode设置为adjustNothing,则没有任何事件有效。
removeListener()
jsx
static removeListener(eventName, callback)
移除某个类型事件的监听函数。
参数:
| 名称 | 类型 | Required | 说明 |
|---|---|---|---|
| eventName | string | Yes | 要移除监听函数的原生事件类型名称 |
| callback | function | Yes | 要移除的监听函数 |
removeAllListeners()
jsx
static removeAllListeners(eventName)
移除某个类型事件的所有监听函数。
dismiss()
jsx
static dismiss()
把弹出的键盘收回去,同时使当前的文本框失去焦点。
scheduleLayoutAnimation
jsx
static scheduleLayoutAnimation(event)
Useful for syncing TextInput (or other keyboard accessory view) size of position changes with keyboard movements.