From c5217f199dfc9db0908a5e4439b7c6b45e17a850 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Mon, 19 Sep 2022 14:56:36 -0700 Subject: [PATCH] Update Keyboard, Alert TS Types Summary: Changelog: [Internal] - Update changes to Keyboard, Alert from differences in those files from https://github.com/facebook/react-native/compare/0.70-stable...main Reviewed By: NickGerleman Differential Revision: D39629997 fbshipit-source-id: 85bb91d00a165e708dbf4e32d7f37ce8a6c02a72 --- types/__typetests__/index.tsx | 4 ++++ types/index.d.ts | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/types/__typetests__/index.tsx b/types/__typetests__/index.tsx index b735c71f82..f7e8c159e5 100644 --- a/types/__typetests__/index.tsx +++ b/types/__typetests__/index.tsx @@ -1066,6 +1066,7 @@ Alert.prompt( }, { text: 'OK', + isPreferred: true, onPress: password => console.log('OK Pressed, password: ' + password), }, ], @@ -1661,6 +1662,9 @@ const KeyboardTest = () => { startCoordinates: {screenX: 0, screenY: 0, width: 0, height: 0}, isEventFromThisApp: true, }); + if (Keyboard.isVisible()) { + Keyboard.metrics(); + } }; const PermissionsAndroidTest = () => { diff --git a/types/index.d.ts b/types/index.d.ts index d65cc9bf36..760f537fd9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7799,6 +7799,7 @@ export interface AccessibilityInfoStatic { export interface AlertButton { text?: string | undefined; onPress?: ((value?: string) => void) | undefined; + isPreferred?: boolean; style?: 'default' | 'cancel' | 'destructive' | undefined; } @@ -10194,7 +10195,7 @@ export type KeyboardEventEasing = | 'linear' | 'keyboard'; -type ScreenRect = { +type KeyboardMetrics = { screenX: number; screenY: number; width: number; @@ -10205,7 +10206,7 @@ interface KeyboardEventIOS { /** * @platform ios */ - startCoordinates: ScreenRect; + startCoordinates: KeyboardMetrics; /** * @platform ios */ @@ -10221,7 +10222,7 @@ export interface KeyboardEvent extends Partial { * Always set to "keyboard" on Android. */ easing: KeyboardEventEasing; - endCoordinates: ScreenRect; + endCoordinates: KeyboardMetrics; } type KeyboardEventListener = (event: KeyboardEvent) => void; @@ -10263,6 +10264,16 @@ export interface KeyboardStatic extends NativeEventEmitter { * 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; } /**