mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add flow definitions for Alert and align them with TypeScript (#49006)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49006 Changelog: [Internal] Reviewed By: huntie Differential Revision: D68774525 fbshipit-source-id: 509f26b0f5f0d309502681f3228ae519689d480a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8058aab0d6
commit
5d7fedacd0
@@ -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;
|
||||
+4
-30
@@ -9,45 +9,19 @@
|
||||
*/
|
||||
|
||||
import type {DialogOptions} from '../NativeModules/specs/NativeDialogManagerAndroid';
|
||||
import type {AlertOptions, AlertType, Buttons} from './Alert.flow';
|
||||
|
||||
import Platform from '../Utilities/Platform';
|
||||
import RCTAlertManager from './RCTAlertManager';
|
||||
|
||||
export type AlertType =
|
||||
| 'default'
|
||||
| 'plain-text'
|
||||
| 'secure-text'
|
||||
| 'login-password';
|
||||
export type AlertButtonStyle = 'default' | 'cancel' | 'destructive';
|
||||
export type AlertButton = {
|
||||
text?: string,
|
||||
onPress?: ?Function,
|
||||
isPreferred?: boolean,
|
||||
style?: AlertButtonStyle,
|
||||
...
|
||||
};
|
||||
export type Buttons = Array<AlertButton>;
|
||||
export type * from './Alert.flow';
|
||||
|
||||
type Options = {
|
||||
/** @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
|
||||
*/
|
||||
class Alert {
|
||||
static alert(
|
||||
title: ?string,
|
||||
message?: ?string,
|
||||
buttons?: Buttons,
|
||||
options?: Options,
|
||||
options?: AlertOptions,
|
||||
): void {
|
||||
if (Platform.OS === 'ios') {
|
||||
Alert.prompt(
|
||||
@@ -126,7 +100,7 @@ class Alert {
|
||||
type?: ?AlertType = 'plain-text',
|
||||
defaultValue?: string,
|
||||
keyboardType?: string,
|
||||
options?: Options,
|
||||
options?: AlertOptions,
|
||||
): void {
|
||||
if (Platform.OS === 'ios') {
|
||||
let callbacks: Array<?any> = [];
|
||||
|
||||
@@ -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;
|
||||
@@ -35,7 +35,7 @@ declare export default typeof NativeActionSheetManager;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Alert/Alert.js 1`] = `
|
||||
exports[`public API should not change unintentionally Libraries/Alert/Alert.flow.js 1`] = `
|
||||
"export type AlertType =
|
||||
| \\"default\\"
|
||||
| \\"plain-text\\"
|
||||
@@ -44,13 +44,13 @@ exports[`public API should not change unintentionally Libraries/Alert/Alert.js 1
|
||||
export type AlertButtonStyle = \\"default\\" | \\"cancel\\" | \\"destructive\\";
|
||||
export type AlertButton = {
|
||||
text?: string,
|
||||
onPress?: ?Function,
|
||||
onPress?: ?((value?: string) => any) | ?Function,
|
||||
isPreferred?: boolean,
|
||||
style?: AlertButtonStyle,
|
||||
...
|
||||
};
|
||||
export type Buttons = Array<AlertButton>;
|
||||
type Options = {
|
||||
export type AlertOptions = {
|
||||
cancelable?: ?boolean,
|
||||
userInterfaceStyle?: \\"unspecified\\" | \\"light\\" | \\"dark\\",
|
||||
onDismiss?: ?() => void,
|
||||
@@ -61,7 +61,7 @@ declare class Alert {
|
||||
title: ?string,
|
||||
message?: ?string,
|
||||
buttons?: Buttons,
|
||||
options?: Options
|
||||
options?: AlertOptions
|
||||
): void;
|
||||
static prompt(
|
||||
title: ?string,
|
||||
@@ -70,7 +70,30 @@ declare class Alert {
|
||||
type?: ?AlertType,
|
||||
defaultValue?: string,
|
||||
keyboardType?: string,
|
||||
options?: Options
|
||||
options?: AlertOptions
|
||||
): void;
|
||||
}
|
||||
declare export default typeof Alert;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Alert/Alert.js 1`] = `
|
||||
"export type * from \\"./Alert.flow\\";
|
||||
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;
|
||||
}
|
||||
declare export default typeof Alert;
|
||||
@@ -83,6 +106,17 @@ declare export default typeof NativeAlertManager;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Alert/RCTAlertManager.flow.js 1`] = `
|
||||
"declare const RCTAlertManager: {
|
||||
alertWithArgs(
|
||||
args: Args,
|
||||
callback: (id: number, value: string) => void
|
||||
): void,
|
||||
};
|
||||
declare export default typeof RCTAlertManager;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Alert/RCTAlertManager.js.flow 1`] = `
|
||||
"declare export default {
|
||||
alertWithArgs(
|
||||
|
||||
Reference in New Issue
Block a user