键盘
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
Keyboard 模块用于控制键盘事件。
使用示例
Keyboard 模块允许您监听原生事件并作出响应,还可以对键盘进行更改(例如将其关闭)。
参考
方法
addListener()
tsx
static addListener: (
eventType: KeyboardEventName,
listener: KeyboardEventListener,
) => EmitterSubscription;
addListener 函数用于将 JavaScript 函数连接到指定的原生键盘通知事件。
该函数会返回监听器的引用。
参数:
| Name | Type | Description |
|---|---|---|
| eventName Required | string | The string that identifies the event you're listening for. See the list below. |
| callback Required | function | The function to be called when the event fires |
eventName
可以是以下任意事件:
-
keyboardWillShow -
keyboardDidShow -
keyboardWillHide -
keyboardDidHide -
keyboardWillChangeFrame -
keyboardDidChangeFrame
备注
在 Android 上,仅支持 keyboardDidShow 和 keyboardDidHide 事件。当使用 Android 10 或更低版本时,如果您的 activity 将 android:windowSoftInputMode 设置为 adjustResize 或 adjustNothing,这些事件将不会被触发。
dismiss()
tsx
static dismiss();
关闭当前键盘并移除焦点。
scheduleLayoutAnimation
tsx
static scheduleLayoutAnimation(event: KeyboardEvent);
用于同步 TextInput(或其他键盘辅助视图)的尺寸或位置变化与键盘移动。
isVisible()
tsx
static isVisible(): boolean;
获取键盘最后已知的可见状态。
metrics()
tsx
static metrics(): KeyboardMetrics | undefined;
返回当前可见软键盘的尺寸信息。