diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 4b06119df2..2be1a48992 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -16,6 +16,7 @@ // Kacper Wiszczuk // Ryan Nickel // Souvik Ghosh +// Cheng Gibson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -8995,8 +8996,44 @@ export interface ARTStatic { Text: typeof ARTText; } +export type KeyboardEventName = + | "keyboardWillShow" + | "keyboardDidShow" + | "keyboardWillHide" + | "keyboardDidHide" + | "keyboardWillChangeFrame" + | "keyboardDidChangeFrame"; + +export type KeyboardEventEasing = + | "easeIn" + | "easeInEaseOut" + | "easeOut" + | "linear" + | "keyboard"; + +type ScreenRect = { + screenX: number; + screenY: number; + width: number; + height: number; +}; + +export interface KeyboardEvent { + duration: number; + easing: KeyboardEventEasing; + endCoordinates: ScreenRect; + startCoordinates: ScreenRect; + isEventFromThisApp: boolean; +} + +type KeyboardEventListener = (event: KeyboardEvent) => void; + export interface KeyboardStatic extends NativeEventEmitter { dismiss: () => void; + addListener( + eventType: KeyboardEventName, + listener: KeyboardEventListener + ): EmitterSubscription; } ////////////////////////////////////////////////////////////////////////// diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 801565dc8d..dfa327ce7b 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -85,6 +85,7 @@ import { DatePickerAndroid, ViewPropTypes, requireNativeComponent, + Keyboard, } from "react-native"; declare module "react-native" { @@ -843,3 +844,8 @@ const ShareTest = () => { } }); }; + +const KeyboardTest = () => { + const subscriber = Keyboard.addListener("keyboardDidHide", (event) => {event}); + subscriber.remove(); +}