Files
react-native/Libraries/Components/Keyboard/Keyboard.d.ts
T
Nick Gerleman 8cdc9e7f04 Place TypeScript Declarations Alongside Source Files
Summary:
React Native's TS definitions are currently mostly stored in one monolithic file. This change splits the definitions up to correspond to the source files they came from, and are placed next to the source files. I think this should help inform, and make it easy to update the TS declarations when touching the Flow file.

I noticed as part of the change that the typings have not yet removed many APIs that were removed from RN. This is bad, since it means using the removed/non-functional API doesn't cause typechecker errors. Locating typings next to source should prevent that from being able to happen.

The organization here means individual TS declarations can declare what will be in the RN entrypoint, which is a little confusing. Seems like a good potential next refactor, beyond the literal translation I did.

Changelog:
[General][Changed] - Place TS Declarations Alongside Source Files

Reviewed By: lunaleaps, rshest

Differential Revision: D39796598

fbshipit-source-id: b36366466fd1976bdd2d4c8f7a4104a33c457a07
2022-09-26 12:09:45 -07:00

110 lines
2.8 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {NativeEventEmitter} from '../../EventEmitter/NativeEventEmitter';
import {EmitterSubscription} from '../../vendor/emitter/EventEmitter';
export type KeyboardEventName =
| 'keyboardWillShow'
| 'keyboardDidShow'
| 'keyboardWillHide'
| 'keyboardDidHide'
| 'keyboardWillChangeFrame'
| 'keyboardDidChangeFrame';
export type KeyboardEventEasing =
| 'easeIn'
| 'easeInEaseOut'
| 'easeOut'
| 'linear'
| 'keyboard';
type KeyboardMetrics = {
screenX: number;
screenY: number;
width: number;
height: number;
};
interface KeyboardEventIOS {
/**
* @platform ios
*/
startCoordinates: KeyboardMetrics;
/**
* @platform ios
*/
isEventFromThisApp: boolean;
}
export interface KeyboardEvent extends Partial<KeyboardEventIOS> {
/**
* Always set to 0 on Android.
*/
duration: number;
/**
* Always set to "keyboard" on Android.
*/
easing: KeyboardEventEasing;
endCoordinates: KeyboardMetrics;
}
type KeyboardEventListener = (event: KeyboardEvent) => void;
export interface KeyboardStatic extends NativeEventEmitter {
/**
* Dismisses the active keyboard and removes focus.
*/
dismiss: () => void;
/**
* The `addListener` function connects a JavaScript function to an identified native
* keyboard notification event.
*
* This function then returns the reference to the listener.
*
* {string} eventName The `nativeEvent` is the string that identifies the event you're listening for. This
*can be any of the following:
*
* - `keyboardWillShow`
* - `keyboardDidShow`
* - `keyboardWillHide`
* - `keyboardDidHide`
* - `keyboardWillChangeFrame`
* - `keyboardDidChangeFrame`
*
* Note that if you set `android:windowSoftInputMode` to `adjustResize` or `adjustNothing`,
* only `keyboardDidShow` and `keyboardDidHide` events will be available on Android.
* `keyboardWillShow` as well as `keyboardWillHide` are generally not available on Android
* since there is no native corresponding event.
*
* {function} callback function to be called when the event fires.
*/
addListener: (
eventType: KeyboardEventName,
listener: KeyboardEventListener,
) => EmitterSubscription;
/**
* Useful for syncing TextInput (or other keyboard accessory view) size of
* position changes with keyboard movements.
*/
scheduleLayoutAnimation: (event: KeyboardEvent) => void;
/**
* Whether the keyboard is last known to be visible.
*/
isVisible(): boolean;
/**
* Return the metrics of the soft-keyboard if visible.
*/
metrics(): KeyboardMetrics | undefined;
}
export const Keyboard: KeyboardStatic;