2015-03-14 00:48:31 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-03-14 00:48:31 +00:00
|
|
|
*
|
|
|
|
* @providesModule AlertIOS
|
|
|
|
* @flow
|
2016-06-21 21:22:44 +00:00
|
|
|
* @jsdoc
|
2015-03-14 00:48:31 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-18 05:22:03 +00:00
|
|
|
var RCTAlertManager = require('NativeModules').AlertManager;
|
2015-03-14 00:48:31 +00:00
|
|
|
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* An Alert button type
|
|
|
|
*/
|
2015-12-17 19:09:22 +00:00
|
|
|
export type AlertType = $Enum<{
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Default alert with no inputs
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'default': string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Plain text input alert
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'plain-text': string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Secure text input alert
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'secure-text': string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Login and password alert
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'login-password': string,
|
2015-12-01 02:44:06 +00:00
|
|
|
}>;
|
|
|
|
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* An Alert button style
|
|
|
|
*/
|
2015-12-17 19:09:22 +00:00
|
|
|
export type AlertButtonStyle = $Enum<{
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Default button style
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'default': string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Cancel button style
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'cancel': string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Destructive button style
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
'destructive': string,
|
2015-12-01 02:44:06 +00:00
|
|
|
}>;
|
2015-03-14 00:48:31 +00:00
|
|
|
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Array or buttons
|
|
|
|
* @typedef {Array} ButtonsArray
|
|
|
|
* @property {string=} text Button label
|
|
|
|
* @property {Function=} onPress Callback function when button pressed
|
|
|
|
* @property {AlertButtonStyle=} style Button style
|
|
|
|
*/
|
2017-03-06 20:44:10 +00:00
|
|
|
export type ButtonsArray = Array<{
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Button label
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
text?: string,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Callback function when button pressed
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
onPress?: ?Function,
|
2016-06-21 21:22:44 +00:00
|
|
|
/**
|
|
|
|
* Button style
|
|
|
|
*/
|
2016-08-09 13:32:41 +00:00
|
|
|
style?: AlertButtonStyle,
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
}>;
|
|
|
|
|
2015-03-14 00:48:31 +00:00
|
|
|
/**
|
2016-06-21 21:22:44 +00:00
|
|
|
* @description
|
|
|
|
* `AlertIOS` provides functionality to create an iOS alert dialog with a
|
|
|
|
* message or create a prompt for user input.
|
|
|
|
*
|
|
|
|
* Creating an iOS alert:
|
2015-04-04 17:14:29 +00:00
|
|
|
*
|
2016-06-21 21:22:44 +00:00
|
|
|
* ```
|
|
|
|
* AlertIOS.alert(
|
|
|
|
* 'Sync Complete',
|
|
|
|
* 'All your data are belong to us.'
|
|
|
|
* );
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Creating an iOS prompt:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* AlertIOS.prompt(
|
|
|
|
* 'Enter a value',
|
|
|
|
* null,
|
|
|
|
* text => console.log("You entered "+text)
|
|
|
|
* );
|
|
|
|
* ```
|
|
|
|
*
|
2017-01-31 20:07:15 +00:00
|
|
|
* We recommend using the [`Alert.alert`](docs/alert.html) method for
|
2016-06-21 21:22:44 +00:00
|
|
|
* cross-platform support if you don't need to create iOS-only prompts.
|
2015-12-18 14:10:09 +00:00
|
|
|
*
|
2015-03-14 00:48:31 +00:00
|
|
|
*/
|
|
|
|
class AlertIOS {
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
/**
|
2016-06-21 21:22:44 +00:00
|
|
|
* Create and display a popup alert.
|
|
|
|
* @static
|
|
|
|
* @method alert
|
|
|
|
* @param title The dialog's title.
|
|
|
|
* @param message An optional message that appears below
|
|
|
|
* the dialog's title.
|
|
|
|
* @param callbackOrButtons This optional argument should
|
|
|
|
* be either a single-argument function or an array of buttons. If passed
|
|
|
|
* a function, it will be called when the user taps 'OK'.
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*
|
|
|
|
* If passed an array of button configurations, each button should include
|
2016-06-21 21:22:44 +00:00
|
|
|
* a `text` key, as well as optional `onPress` and `style` keys. `style`
|
|
|
|
* should be one of 'default', 'cancel' or 'destructive'.
|
|
|
|
* @param type Deprecated, do not use.
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*
|
2016-06-21 21:22:44 +00:00
|
|
|
* @example <caption>Example with custom buttons</caption>
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*
|
|
|
|
* AlertIOS.alert(
|
2016-06-21 21:22:44 +00:00
|
|
|
* 'Update available',
|
|
|
|
* 'Keep your app up to date to enjoy the latest features',
|
|
|
|
* [
|
|
|
|
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
|
|
|
|
* {text: 'Install', onPress: () => console.log('Install Pressed')},
|
|
|
|
* ],
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
* );
|
|
|
|
*/
|
2015-03-14 00:48:31 +00:00
|
|
|
static alert(
|
|
|
|
title: ?string,
|
2015-03-23 18:36:57 +00:00
|
|
|
message?: ?string,
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
callbackOrButtons?: ?(() => void) | ButtonsArray,
|
|
|
|
type?: AlertType,
|
2015-03-14 00:48:31 +00:00
|
|
|
): void {
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
if (typeof type !== 'undefined') {
|
|
|
|
console.warn('AlertIOS.alert() with a 4th "type" parameter is deprecated and will be removed. Use AlertIOS.prompt() instead.');
|
|
|
|
this.prompt(title, message, callbackOrButtons, type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.prompt(title, message, callbackOrButtons, 'default');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-21 21:22:44 +00:00
|
|
|
* Create and display a prompt to enter some text.
|
|
|
|
* @static
|
|
|
|
* @method prompt
|
|
|
|
* @param title The dialog's title.
|
|
|
|
* @param message An optional message that appears above the text
|
|
|
|
* input.
|
|
|
|
* @param callbackOrButtons This optional argument should
|
|
|
|
* be either a single-argument function or an array of buttons. If passed
|
|
|
|
* a function, it will be called with the prompt's value when the user
|
|
|
|
* taps 'OK'.
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*
|
|
|
|
* If passed an array of button configurations, each button should include
|
2016-06-21 21:22:44 +00:00
|
|
|
* a `text` key, as well as optional `onPress` and `style` keys (see
|
|
|
|
* example). `style` should be one of 'default', 'cancel' or 'destructive'.
|
|
|
|
* @param type This configures the text input. One of 'plain-text',
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
* 'secure-text' or 'login-password'.
|
2016-07-15 02:24:47 +00:00
|
|
|
* @param defaultValue The default text in text input.
|
2017-01-19 22:29:39 +00:00
|
|
|
* @param keyboardType The keyboard type of first text field(if exists).
|
|
|
|
* One of 'default', 'email-address', 'numeric', 'phone-pad',
|
|
|
|
* 'ascii-capable', 'numbers-and-punctuation', 'url', 'number-pad',
|
|
|
|
* 'name-phone-pad', 'decimal-pad', 'twitter' or 'web-search'.
|
2016-06-21 21:22:44 +00:00
|
|
|
*
|
|
|
|
* @example <caption>Example with custom buttons</caption>
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*
|
|
|
|
* AlertIOS.prompt(
|
|
|
|
* 'Enter password',
|
|
|
|
* 'Enter your password to claim your $1.5B in lottery winnings',
|
|
|
|
* [
|
|
|
|
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
|
|
|
|
* {text: 'OK', onPress: password => console.log('OK Pressed, password: ' + password)},
|
|
|
|
* ],
|
|
|
|
* 'secure-text'
|
|
|
|
* );
|
|
|
|
*
|
2016-06-21 21:22:44 +00:00
|
|
|
* @example <caption>Example with the default button and a custom callback</caption>
|
|
|
|
*
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
* AlertIOS.prompt(
|
|
|
|
* 'Update username',
|
|
|
|
* null,
|
|
|
|
* text => console.log("Your username is "+text),
|
|
|
|
* null,
|
|
|
|
* 'default'
|
2016-06-21 21:22:44 +00:00
|
|
|
* );
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
*/
|
|
|
|
static prompt(
|
|
|
|
title: ?string,
|
|
|
|
message?: ?string,
|
|
|
|
callbackOrButtons?: ?((text: string) => void) | ButtonsArray,
|
|
|
|
type?: ?AlertType = 'plain-text',
|
|
|
|
defaultValue?: string,
|
2017-01-19 22:29:39 +00:00
|
|
|
keyboardType?: string
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
): void {
|
|
|
|
if (typeof type === 'function') {
|
|
|
|
console.warn(
|
|
|
|
'You passed a callback function as the "type" argument to AlertIOS.prompt(). React Native is ' +
|
|
|
|
'assuming you want to use the deprecated AlertIOS.prompt(title, defaultValue, buttons, callback) ' +
|
2017-01-19 22:29:39 +00:00
|
|
|
'signature. The current signature is AlertIOS.prompt(title, message, callbackOrButtons, type, defaultValue, ' +
|
|
|
|
'keyboardType) and the old syntax will be removed in a future version.');
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
|
|
|
|
var callback = type;
|
|
|
|
var defaultValue = message;
|
|
|
|
RCTAlertManager.alertWithArgs({
|
|
|
|
title: title || undefined,
|
|
|
|
type: 'plain-text',
|
|
|
|
defaultValue,
|
|
|
|
}, (id, value) => {
|
|
|
|
callback(value);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:48:31 +00:00
|
|
|
var callbacks = [];
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
var buttons = [];
|
2015-12-01 02:44:06 +00:00
|
|
|
var cancelButtonKey;
|
|
|
|
var destructiveButtonKey;
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
if (typeof callbackOrButtons === 'function') {
|
|
|
|
callbacks = [callbackOrButtons];
|
|
|
|
}
|
|
|
|
else if (callbackOrButtons instanceof Array) {
|
|
|
|
callbackOrButtons.forEach((btn, index) => {
|
|
|
|
callbacks[index] = btn.onPress;
|
|
|
|
if (btn.style === 'cancel') {
|
|
|
|
cancelButtonKey = String(index);
|
|
|
|
} else if (btn.style === 'destructive') {
|
|
|
|
destructiveButtonKey = String(index);
|
|
|
|
}
|
|
|
|
if (btn.text || index < (callbackOrButtons || []).length - 1) {
|
|
|
|
var btnDef = {};
|
|
|
|
btnDef[index] = btn.text || '';
|
|
|
|
buttons.push(btnDef);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:48:31 +00:00
|
|
|
RCTAlertManager.alertWithArgs({
|
2015-12-01 02:44:06 +00:00
|
|
|
title: title || undefined,
|
|
|
|
message: message || undefined,
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
buttons,
|
2015-12-01 02:44:06 +00:00
|
|
|
type: type || undefined,
|
Simplified AlertIOS
Summary:
Ok, so this started as fixing #5273 but ended up getting a little more complicated. :smile:
Currently, AlertIOS has the following API:
* `alert(title, message, buttons, type)`
* `prompt(title, defaultValue, buttons, callback)`
I've changed the API to look like the following:
* `alert(title, message, callbackOrButtons)`
* `prompt(title, message, callbackOrButtons, type, defaultValue)`
I know that breaking changes are a big deal, but I find the current alert API to be fairly inconsistent and unnecessarily confusing. I'll try to justify my changes one by one:
1. Currently `type` is an optional parameter of `alert`. However, the only reason to change the alert type from the default is in order to create one of the input dialogs (text, password or username/password). So we're in a weird state where if you want a normal text input, you use `prompt`, but if you want a password input you use `alert` with the 'secure-text' type. I've moved `type` to `prompt` so all text input is now done with `pro
Closes https://github.com/facebook/react-native/pull/5286
Reviewed By: svcscm
Differential Revision: D2850400
Pulled By: androidtrunkagent
fb-gh-sync-id: 2986cfa2266225df7e4dcd703fce1e322c12b816
2016-01-21 18:48:58 +00:00
|
|
|
defaultValue,
|
2015-12-01 02:44:06 +00:00
|
|
|
cancelButtonKey,
|
|
|
|
destructiveButtonKey,
|
2017-01-19 22:29:39 +00:00
|
|
|
keyboardType,
|
2015-05-11 23:40:04 +00:00
|
|
|
}, (id, value) => {
|
2015-03-14 00:48:31 +00:00
|
|
|
var cb = callbacks[id];
|
2015-05-11 23:40:04 +00:00
|
|
|
cb && cb(value);
|
2015-03-14 00:48:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AlertIOS;
|