-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flow definitions for Alert and align them with TypeScript (#49006)
Summary: Pull Request resolved: #49006 Changelog: [Internal] Reviewed By: huntie Differential Revision: D68774525 fbshipit-source-id: 509f26b0f5f0d309502681f3228ae519689d480a
- Loading branch information
1 parent
8058aab
commit 5d7feda
Showing
4 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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 | ||
* @flow | ||
*/ | ||
|
||
export type AlertType = | ||
| 'default' | ||
| 'plain-text' | ||
| 'secure-text' | ||
| 'login-password'; | ||
|
||
export type AlertButtonStyle = 'default' | 'cancel' | 'destructive'; | ||
|
||
export type AlertButton = { | ||
text?: string, | ||
onPress?: ?((value?: string) => any) | ?Function, | ||
isPreferred?: boolean, | ||
style?: AlertButtonStyle, | ||
... | ||
}; | ||
|
||
export type Buttons = Array<AlertButton>; | ||
|
||
export type AlertOptions = { | ||
/** @platform android */ | ||
cancelable?: ?boolean, | ||
userInterfaceStyle?: 'unspecified' | 'light' | 'dark', | ||
/** @platform android */ | ||
onDismiss?: ?() => void, | ||
... | ||
}; | ||
|
||
/** | ||
* Launches an alert dialog with the specified title and message. | ||
* | ||
* See https://reactnative.dev/docs/alert | ||
*/ | ||
declare class Alert { | ||
static alert( | ||
title: ?string, | ||
message?: ?string, | ||
buttons?: Buttons, | ||
options?: AlertOptions, | ||
): void; | ||
|
||
static prompt( | ||
title: ?string, | ||
message?: ?string, | ||
callbackOrButtons?: ?(((text: string) => void) | Buttons), | ||
type?: ?AlertType, | ||
defaultValue?: string, | ||
keyboardType?: string, | ||
options?: AlertOptions, | ||
): void; | ||
} | ||
|
||
export default Alert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/react-native/Libraries/Alert/RCTAlertManager.flow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* 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 | ||
* @flow strict-local | ||
*/ | ||
|
||
import type {Args} from './NativeAlertManager'; | ||
|
||
declare const RCTAlertManager: { | ||
alertWithArgs( | ||
args: Args, | ||
callback: (id: number, value: string) => void, | ||
): void, | ||
}; | ||
|
||
export default RCTAlertManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters