|
9 | 9 | */ |
10 | 10 |
|
11 | 11 | import type {DialogOptions} from '../NativeModules/specs/NativeDialogManagerAndroid'; |
| 12 | +import type {AlertButtons, AlertOptions, AlertType} from './AlertTypes.flow'; |
12 | 13 |
|
13 | 14 | import Platform from '../Utilities/Platform'; |
14 | 15 | import RCTAlertManager from './RCTAlertManager'; |
15 | 16 |
|
16 | | -export type AlertType = |
17 | | - | 'default' |
18 | | - | 'plain-text' |
19 | | - | 'secure-text' |
20 | | - | 'login-password'; |
21 | | -export type AlertButtonStyle = 'default' | 'cancel' | 'destructive'; |
22 | | -export type Buttons = Array<{ |
23 | | - text?: string, |
24 | | - onPress?: ?Function, |
25 | | - isPreferred?: boolean, |
26 | | - style?: AlertButtonStyle, |
27 | | - ... |
28 | | -}>; |
29 | | -// [macOS |
30 | | -export type DefaultInputsArray = Array<{ |
31 | | - default?: string, |
32 | | - placeholder?: string, |
33 | | - style?: AlertButtonStyle, |
34 | | -}>; |
35 | | -// macOS] |
36 | | - |
37 | | -type Options = { |
38 | | - cancelable?: ?boolean, |
39 | | - userInterfaceStyle?: 'unspecified' | 'light' | 'dark', |
40 | | - onDismiss?: ?() => void, |
41 | | - // [macOS |
42 | | - modal?: ?boolean, |
43 | | - critical?: ?boolean, |
44 | | - // macOS] |
45 | | - ... |
46 | | -}; |
47 | | - |
48 | | -/** |
49 | | - * Launches an alert dialog with the specified title and message. |
50 | | - * |
51 | | - * See https://reactnative.dev/docs/alert |
52 | | - */ |
53 | 17 | class Alert { |
54 | 18 | static alert( |
55 | 19 | title: ?string, |
56 | 20 | message?: ?string, |
57 | | - buttons?: Buttons, |
58 | | - options?: Options, |
| 21 | + buttons?: AlertButtons, |
| 22 | + options?: AlertOptions, |
59 | 23 | ): void { |
60 | 24 | if (Platform.OS === 'ios') { |
61 | 25 | Alert.prompt( |
@@ -99,7 +63,7 @@ class Alert { |
99 | 63 | // At most three buttons (neutral, negative, positive). Ignore rest. |
100 | 64 | // The text 'OK' should be probably localized. iOS Alert does that in native. |
101 | 65 | const defaultPositiveText = 'OK'; |
102 | | - const validButtons: Buttons = buttons |
| 66 | + const validButtons: AlertButtons = buttons |
103 | 67 | ? buttons.slice(0, 3) |
104 | 68 | : [{text: defaultPositiveText}]; |
105 | 69 | const buttonPositive = validButtons.pop(); |
@@ -142,11 +106,11 @@ class Alert { |
142 | 106 | static prompt( |
143 | 107 | title: ?string, |
144 | 108 | message?: ?string, |
145 | | - callbackOrButtons?: ?(((text: string) => void) | Buttons), |
| 109 | + callbackOrButtons?: ?(((text: string) => void) | AlertButtons), |
146 | 110 | type?: ?AlertType = 'plain-text', |
147 | 111 | defaultValue?: string, |
148 | 112 | keyboardType?: string, |
149 | | - options?: Options, |
| 113 | + options?: AlertOptions, |
150 | 114 | ): void { |
151 | 115 | if (Platform.OS === 'ios') { |
152 | 116 | let callbacks: Array<?any> = []; |
@@ -252,7 +216,7 @@ class Alert { |
252 | 216 | static promptMacOS( |
253 | 217 | title: ?string, |
254 | 218 | message?: ?string, |
255 | | - callbackOrButtons?: ?((text: string) => void) | Buttons, |
| 219 | + callbackOrButtons?: ?((text: string) => void) | AlertButtons, |
256 | 220 | type?: ?AlertType = 'plain-text', |
257 | 221 | defaultInputs?: DefaultInputsArray, |
258 | 222 | modal?: ?boolean, |
@@ -292,4 +256,4 @@ class Alert { |
292 | 256 | // macOS] |
293 | 257 | } |
294 | 258 |
|
295 | | -module.exports = Alert; |
| 259 | +export default Alert; |
0 commit comments