2015-03-14 17:52:40 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2015-03-14 17:52:40 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-03-14 17:52:40 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {StyleSheet, View, Text, TouchableHighlight, AlertIOS} = ReactNative;
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
var {SimpleAlertExampleBlock} = require('./AlertExample');
|
2015-12-17 19:09:22 +00:00
|
|
|
|
2015-03-14 17:52:40 +00:00
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = 'AlertIOS';
|
|
|
|
exports.description = 'iOS alerts and action sheets';
|
2018-05-11 20:32:37 +00:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Alerts',
|
|
|
|
render() {
|
|
|
|
return <SimpleAlertExampleBlock />;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Prompt Options',
|
|
|
|
render(): React.Element<any> {
|
|
|
|
return <PromptOptions />;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Prompt Types',
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() => AlertIOS.prompt('Plain Text Entry')}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>plain-text</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt('Secure Text', null, null, 'secure-text')
|
|
|
|
}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>secure-text</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt('Login & Password', null, null, 'login-password')
|
|
|
|
}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>login-password</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class PromptOptions extends React.Component<$FlowFixMeProps, any> {
|
2016-02-25 10:44:58 +00:00
|
|
|
customButtons: Array<Object>;
|
|
|
|
|
2015-05-11 23:40:04 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2016-02-25 10:44:58 +00:00
|
|
|
// $FlowFixMe this seems to be a Flow bug, `saveResponse` is defined below
|
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
|
|
|
this.saveResponse = this.saveResponse.bind(this);
|
2015-05-11 23:40:04 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
this.customButtons = [
|
|
|
|
{
|
|
|
|
text: 'Custom OK',
|
|
|
|
onPress: this.saveResponse,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Custom Cancel',
|
|
|
|
style: 'cancel',
|
|
|
|
},
|
|
|
|
];
|
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
|
|
|
|
|
|
|
this.state = {
|
|
|
|
promptValue: undefined,
|
|
|
|
};
|
2015-05-11 23:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text style={{marginBottom: 10}}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={{fontWeight: 'bold'}}>Prompt value:</Text>{' '}
|
|
|
|
{this.state.promptValue}
|
2015-05-11 23:40:04 +00:00
|
|
|
</Text>
|
|
|
|
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
2018-05-11 20:32:37 +00:00
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt('Type a value', null, this.saveResponse)
|
|
|
|
}>
|
2015-05-11 23:40:04 +00:00
|
|
|
<View style={styles.button}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>prompt with title & callback</Text>
|
2015-05-11 23:40:04 +00:00
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
2018-05-11 20:32:37 +00:00
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt('Type a value', null, this.customButtons)
|
|
|
|
}>
|
2015-05-11 23:40:04 +00:00
|
|
|
<View style={styles.button}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>prompt with title & custom buttons</Text>
|
2015-05-11 23:40:04 +00:00
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
|
|
|
|
<TouchableHighlight
|
2017-01-19 22:29:39 +00:00
|
|
|
style={styles.wrapper}
|
2018-05-11 20:32:37 +00:00
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt(
|
|
|
|
'Type a phone number',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'plain-text',
|
|
|
|
undefined,
|
|
|
|
'phone-pad',
|
|
|
|
)
|
|
|
|
}>
|
2017-01-19 22:29:39 +00:00
|
|
|
<View style={styles.button}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>prompt with title & custom keyboard</Text>
|
2017-01-19 22:29:39 +00:00
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
|
|
|
|
<TouchableHighlight
|
2015-05-11 23:40:04 +00:00
|
|
|
style={styles.wrapper}
|
2018-05-11 20:32:37 +00:00
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt(
|
|
|
|
'Type a value',
|
|
|
|
null,
|
|
|
|
this.saveResponse,
|
|
|
|
undefined,
|
|
|
|
'Default value',
|
|
|
|
)
|
|
|
|
}>
|
2015-05-11 23:40:04 +00:00
|
|
|
<View style={styles.button}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>prompt with title, callback & default value</Text>
|
2015-05-11 23:40:04 +00:00
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
2018-05-11 20:32:37 +00:00
|
|
|
onPress={() =>
|
|
|
|
AlertIOS.prompt(
|
|
|
|
'Type a value',
|
|
|
|
null,
|
|
|
|
this.customButtons,
|
|
|
|
'login-password',
|
|
|
|
'admin@site.com',
|
|
|
|
)
|
|
|
|
}>
|
2015-05-11 23:40:04 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<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
|
|
|
prompt with title, custom buttons, login/password & default value
|
2015-05-11 23:40:04 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
saveResponse(promptValue) {
|
2018-05-11 20:32:37 +00:00
|
|
|
this.setState({promptValue: JSON.stringify(promptValue)});
|
2015-05-11 23:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-14 17:52:40 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
wrapper: {
|
|
|
|
borderRadius: 5,
|
|
|
|
marginBottom: 5,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
});
|