Skip to main content

Keyboard

Keyboard 模块控制键盘事件。

¥Keyboard module to control keyboard events.

用法

¥Usage

键盘模块允许你监听原生事件并对它们做出反应,以及对键盘进行更改,例如关闭它。

¥The Keyboard module allows you to listen for native events and react to them, as well as make changes to the keyboard, like dismissing it.


参考

¥Reference

方法

¥Methods

addListener()

static addListener: (
eventType: KeyboardEventName,
listener: KeyboardEventListener,
) => EmitterSubscription;

addListener 函数将 JavaScript 函数连接到已识别的原生键盘通知事件。

¥The addListener function connects a JavaScript function to an identified native keyboard notification event.

然后该函数返回对监听器的引用。

¥This function then returns the reference to the listener.

参数:

¥Parameters:

名称类型描述
事件名称
必填
string标识你正在监听的事件的字符串。请参阅下面的列表。
回调
必填
function事件触发时调用的函数

eventName

这可以是以下任意一项:

¥This can be any of the following:

  • keyboardWillShow

  • keyboardDidShow

  • keyboardWillHide

  • keyboardDidHide

  • keyboardWillChangeFrame

  • keyboardDidChangeFrame

请注意,Android 上仅提供 keyboardDidShowkeyboardDidHide 事件。如果你的 Activity 将 android:windowSoftInputMode 设置为 adjustNothing,则使用 Android 10 及以下版本时不会触发这些事件。

¥Note that only keyboardDidShow and keyboardDidHide events are available on Android. The events will not be fired when using Android 10 and under if your activity has android:windowSoftInputMode set to adjustNothing.


dismiss()

static dismiss();

关闭活动键盘并移除焦点。

¥Dismisses the active keyboard and removes focus.


scheduleLayoutAnimation

static scheduleLayoutAnimation(event: KeyboardEvent);

对于同步 TextInput(或其他键盘附件视图)位置大小随键盘移动的变化非常有用。

¥Useful for syncing TextInput (or other keyboard accessory view) size of position changes with keyboard movements.


isVisible()

static isVisible(): boolean;

键盘是否最后一次可见。

¥Whether the keyboard is last known to be visible.


metrics()

static metrics(): KeyboardMetrics | undefined;

返回软键盘的指标(如果可见)。

¥Return the metrics of the soft-keyboard if visible.