2015-12-17 19:09:22 +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-12-17 19:09:22 +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 {Alert, StyleSheet, Text, TouchableHighlight, View} = ReactNative;
|
2015-12-17 19:09:22 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
var RNTesterBlock = require('./RNTesterBlock');
|
2015-12-17 19:09:22 +00:00
|
|
|
|
|
|
|
// corporate ipsum > lorem ipsum
|
2018-05-11 20:32:37 +00:00
|
|
|
var alertMessage =
|
|
|
|
'Credibly reintermediate next-generation potentialities after goal-oriented ' +
|
|
|
|
'catalysts for change. Dynamically revolutionize.';
|
2015-12-17 19:09:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple alert examples.
|
|
|
|
*/
|
2016-07-26 08:00:02 +00:00
|
|
|
class SimpleAlertExampleBlock extends React.Component {
|
|
|
|
render() {
|
2015-12-17 19:09:22 +00:00
|
|
|
return (
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert('Alert Title', alertMessage)}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with message and default button</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert('Alert Title', alertMessage, [
|
2015-12-17 19:09:22 +00:00
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
2018-05-11 20:32:37 +00:00
|
|
|
])
|
|
|
|
}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with one button</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert('Alert Title', alertMessage, [
|
2015-12-17 19:09:22 +00:00
|
|
|
{text: 'Cancel', onPress: () => console.log('Cancel Pressed!')},
|
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
2018-05-11 20:32:37 +00:00
|
|
|
])
|
|
|
|
}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with two buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert('Alert Title', null, [
|
2015-12-17 19:09:22 +00:00
|
|
|
{text: 'Foo', onPress: () => console.log('Foo Pressed!')},
|
|
|
|
{text: 'Bar', onPress: () => console.log('Bar Pressed!')},
|
|
|
|
{text: 'Baz', onPress: () => console.log('Baz Pressed!')},
|
2018-05-11 20:32:37 +00:00
|
|
|
])
|
|
|
|
}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with three buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert(
|
|
|
|
'Foo Title',
|
|
|
|
alertMessage,
|
|
|
|
'..............'.split('').map((dot, index) => ({
|
|
|
|
text: 'Button ' + index,
|
|
|
|
onPress: () => console.log('Pressed ' + index),
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with too many buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
null,
|
|
|
|
[{text: 'OK', onPress: () => console.log('OK Pressed!')}],
|
|
|
|
{
|
|
|
|
cancelable: false,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}>
|
2016-08-09 13:08:44 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert that cannot be dismissed</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.wrapper}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert('', alertMessage, [
|
2017-08-31 00:14:28 +00:00
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
2018-05-11 20:32:37 +00:00
|
|
|
])
|
|
|
|
}>
|
2017-08-31 00:14:28 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert without title</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2015-12-17 19:09:22 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-17 19:09:22 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class AlertExample extends React.Component {
|
|
|
|
static title = 'Alert';
|
|
|
|
|
2018-06-06 12:20:40 +00:00
|
|
|
static description =
|
|
|
|
'Alerts display a concise and informative message ' +
|
|
|
|
'and prompt the user to make a decision.';
|
2016-07-26 08:00:02 +00:00
|
|
|
|
|
|
|
render() {
|
2015-12-17 19:09:22 +00:00
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title={'Alert'}>
|
2015-12-17 19:09:22 +00:00
|
|
|
<SimpleAlertExampleBlock />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-12-17 19:09:22 +00:00
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-12-17 19:09:22 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
wrapper: {
|
|
|
|
borderRadius: 5,
|
|
|
|
marginBottom: 5,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
AlertExample,
|
|
|
|
SimpleAlertExampleBlock,
|
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
|
|
|
};
|