1 | /**
|
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | * @format
|
8 | */
|
9 |
|
10 | import {NativeEventEmitter} from '../../EventEmitter/NativeEventEmitter';
|
11 | import {EmitterSubscription} from '../../vendor/emitter/EventEmitter';
|
12 |
|
13 | export type KeyboardEventName =
|
14 | | 'keyboardWillShow'
|
15 | | 'keyboardDidShow'
|
16 | | 'keyboardWillHide'
|
17 | | 'keyboardDidHide'
|
18 | | 'keyboardWillChangeFrame'
|
19 | | 'keyboardDidChangeFrame';
|
20 |
|
21 | export type KeyboardEventEasing =
|
22 | | 'easeIn'
|
23 | | 'easeInEaseOut'
|
24 | | 'easeOut'
|
25 | | 'linear'
|
26 | | 'keyboard';
|
27 |
|
28 | type KeyboardMetrics = {
|
29 | screenX: number;
|
30 | screenY: number;
|
31 | width: number;
|
32 | height: number;
|
33 | };
|
34 |
|
35 | interface KeyboardEventIOS {
|
36 | /**
|
37 | * @platform ios
|
38 | */
|
39 | startCoordinates: KeyboardMetrics;
|
40 | /**
|
41 | * @platform ios
|
42 | */
|
43 | isEventFromThisApp: boolean;
|
44 | }
|
45 |
|
46 | export interface KeyboardEvent extends Partial<KeyboardEventIOS> {
|
47 | /**
|
48 | * Always set to 0 on Android.
|
49 | */
|
50 | duration: number;
|
51 | /**
|
52 | * Always set to "keyboard" on Android.
|
53 | */
|
54 | easing: KeyboardEventEasing;
|
55 | endCoordinates: KeyboardMetrics;
|
56 | }
|
57 |
|
58 | type KeyboardEventListener = (event: KeyboardEvent) => void;
|
59 |
|
60 | export interface KeyboardStatic extends NativeEventEmitter {
|
61 | /**
|
62 | * Dismisses the active keyboard and removes focus.
|
63 | */
|
64 | dismiss: () => void;
|
65 | /**
|
66 | * The `addListener` function connects a JavaScript function to an identified native
|
67 | * keyboard notification event.
|
68 | *
|
69 | * This function then returns the reference to the listener.
|
70 | *
|
71 | * {string} eventName The `nativeEvent` is the string that identifies the event you're listening for. This
|
72 | *can be any of the following:
|
73 | *
|
74 | * - `keyboardWillShow`
|
75 | * - `keyboardDidShow`
|
76 | * - `keyboardWillHide`
|
77 | * - `keyboardDidHide`
|
78 | * - `keyboardWillChangeFrame`
|
79 | * - `keyboardDidChangeFrame`
|
80 | *
|
81 | * Note that if you set `android:windowSoftInputMode` to `adjustResize` or `adjustNothing`,
|
82 | * only `keyboardDidShow` and `keyboardDidHide` events will be available on Android.
|
83 | * `keyboardWillShow` as well as `keyboardWillHide` are generally not available on Android
|
84 | * since there is no native corresponding event.
|
85 | *
|
86 | * {function} callback function to be called when the event fires.
|
87 | */
|
88 | addListener: (
|
89 | eventType: KeyboardEventName,
|
90 | listener: KeyboardEventListener,
|
91 | ) => EmitterSubscription;
|
92 | /**
|
93 | * Useful for syncing TextInput (or other keyboard accessory view) size of
|
94 | * position changes with keyboard movements.
|
95 | */
|
96 | scheduleLayoutAnimation: (event: KeyboardEvent) => void;
|
97 |
|
98 | /**
|
99 | * Whether the keyboard is last known to be visible.
|
100 | */
|
101 | isVisible(): boolean;
|
102 |
|
103 | /**
|
104 | * Return the metrics of the soft-keyboard if visible.
|
105 | */
|
106 | metrics(): KeyboardMetrics | undefined;
|
107 | }
|
108 |
|
109 | export const Keyboard: KeyboardStatic;
|