88 *
99 * @providesModule AlertIOS
1010 * @flow
11+ * @jsdoc
1112 */
1213'use strict' ;
1314
1415var RCTAlertManager = require ( 'NativeModules' ) . AlertManager ;
1516
17+ /**
18+ * An Alert button type
19+ */
1620export type AlertType = $Enum < {
21+ /**
22+ * Default alert with no inputs
23+ */
1724 'default' : string ;
25+ /**
26+ * Plain text input alert
27+ */
1828 'plain-text' : string ;
29+ /**
30+ * Secure text input alert
31+ */
1932 'secure-text' : string ;
33+ /**
34+ * Login and password alert
35+ */
2036 'login-password' : string ;
2137} > ;
2238
39+ /**
40+ * An Alert button style
41+ */
2342export type AlertButtonStyle = $Enum < {
43+ /**
44+ * Default button style
45+ */
2446 'default' : string ;
47+ /**
48+ * Cancel button style
49+ */
2550 'cancel' : string ;
51+ /**
52+ * Destructive button style
53+ */
2654 'destructive' : string ;
2755} > ;
2856
57+ /**
58+ * Array or buttons
59+ * @typedef {Array } ButtonsArray
60+ * @property {string= } text Button label
61+ * @property {Function= } onPress Callback function when button pressed
62+ * @property {AlertButtonStyle= } style Button style
63+ */
2964type ButtonsArray = Array < {
65+ /**
66+ * Button label
67+ */
3068 text ?: string ;
69+ /**
70+ * Callback function when button pressed
71+ */
3172 onPress ?: ?Function ;
73+ /**
74+ * Button style
75+ */
3276 style ?: AlertButtonStyle ;
3377} > ;
3478
3579/**
36- * The AlertsIOS utility provides two functions: `alert` and `prompt`. All
37- * functionality available through `AlertIOS.alert` is also available in the
38- * cross-platform `Alert.alert`, which we recommend you use if you don't need
39- * iOS-specific functionality.
80+ * @description
81+ * `AlertIOS` provides functionality to create an iOS alert dialog with a
82+ * message or create a prompt for user input.
83+ *
84+ * Creating an iOS alert:
4085 *
41- * `AlertIOS.prompt` allows you to prompt the user for input inside of an
42- * alert popup.
86+ * ```
87+ * AlertIOS.alert(
88+ * 'Sync Complete',
89+ * 'All your data are belong to us.'
90+ * );
91+ * ```
92+ *
93+ * Creating an iOS prompt:
94+ *
95+ * ```
96+ * AlertIOS.prompt(
97+ * 'Enter a value',
98+ * null,
99+ * text => console.log("You entered "+text)
100+ * );
101+ * ```
102+ *
103+ * We recommend using the [`Alert.alert`](/docs/alert.html) method for
104+ * cross-platform support if you don't need to create iOS-only prompts.
43105 *
44106 */
45107class AlertIOS {
46108 /**
47- * Creates a popup to alert the user. See
48- * [Alert](docs/alert.html).
49- *
50- * - title: string -- The dialog's title.
51- * - message: string -- An optional message that appears above the text input.
52- * - callbackOrButtons -- This optional argument should be either a
53- * single-argument function or an array of buttons. If passed a function,
54- * it will be called when the user taps 'OK'.
109+ * Create and display a popup alert.
110+ * @static
111+ * @method alert
112+ * @param title The dialog's title.
113+ * @param message An optional message that appears below
114+ * the dialog's title.
115+ * @param callbackOrButtons This optional argument should
116+ * be either a single-argument function or an array of buttons. If passed
117+ * a function, it will be called when the user taps 'OK'.
55118 *
56119 * If passed an array of button configurations, each button should include
57- * a `text` key, as well as optional `onPress` and `style` keys.
58- * `style` should be one of 'default', 'cancel' or 'destructive'.
59- * - type -- *deprecated , do not use*
120+ * a `text` key, as well as optional `onPress` and `style` keys. `style`
121+ * should be one of 'default', 'cancel' or 'destructive'.
122+ * @param type Deprecated , do not use.
60123 *
61- * Example:
124+ * @example <caption> Example with custom buttons</caption>
62125 *
63- * ```
64126 * AlertIOS.alert(
65- * 'Sync Complete',
66- * 'All your data are belong to us.'
127+ * 'Update available',
128+ * 'Keep your app up to date to enjoy the latest features',
129+ * [
130+ * {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
131+ * {text: 'Install', onPress: () => console.log('Install Pressed')},
132+ * ],
67133 * );
68- * ```
69134 */
70135 static alert (
71136 title : ?string ,
@@ -82,23 +147,26 @@ class AlertIOS {
82147 }
83148
84149 /**
85- * Prompt the user to enter some text.
86- *
87- * - title: string -- The dialog's title.
88- * - message: string -- An optional message that appears above the text input.
89- * - callbackOrButtons -- This optional argument should be either a
90- * single-argument function or an array of buttons. If passed a function,
91- * it will be called with the prompt's value when the user taps 'OK'.
150+ * Create and display a prompt to enter some text.
151+ * @static
152+ * @method prompt
153+ * @param title The dialog's title.
154+ * @param message An optional message that appears above the text
155+ * input.
156+ * @param callbackOrButtons This optional argument should
157+ * be either a single-argument function or an array of buttons. If passed
158+ * a function, it will be called with the prompt's value when the user
159+ * taps 'OK'.
92160 *
93161 * If passed an array of button configurations, each button should include
94- * a `text` key, as well as optional `onPress` and `style` keys (see example).
95- * `style` should be one of 'default', 'cancel' or 'destructive'.
96- * - type: string -- This configures the text input. One of 'plain-text',
162+ * a `text` key, as well as optional `onPress` and `style` keys (see
163+ * example). `style` should be one of 'default', 'cancel' or 'destructive'.
164+ * @param type This configures the text input. One of 'plain-text',
97165 * 'secure-text' or 'login-password'.
98- * - defaultValue: string -- the default value for the text field.
166+ * @param defaultValue The dialog's title.
167+ *
168+ * @example <caption>Example with custom buttons</caption>
99169 *
100- * Example with custom buttons:
101- * ```
102170 * AlertIOS.prompt(
103171 * 'Enter password',
104172 * 'Enter your password to claim your $1.5B in lottery winnings',
@@ -108,18 +176,16 @@ class AlertIOS {
108176 * ],
109177 * 'secure-text'
110178 * );
111- * ```
112179 *
113- * Example with the default button and a custom callback:
114- * ```
180+ * @example <caption> Example with the default button and a custom callback</caption>
181+ *
115182 * AlertIOS.prompt(
116183 * 'Update username',
117184 * null,
118185 * text => console.log("Your username is "+text),
119186 * null,
120187 * 'default'
121- * )
122- * ```
188+ * );
123189 */
124190 static prompt (
125191 title : ?string ,
0 commit comments