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
|
|
|
* 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.
|
|
|
|
*
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule AlertExample
|
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');
|
2015-12-17 19:09:22 +00:00
|
|
|
var {
|
|
|
|
Alert,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = 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
|
|
|
|
var alertMessage = 'Credibly reintermediate next-generation potentialities after goal-oriented ' +
|
|
|
|
'catalysts for change. Dynamically revolutionize.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
alertMessage,
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with message and default button</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
alertMessage,
|
|
|
|
[
|
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
|
|
|
]
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with one button</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
alertMessage,
|
|
|
|
[
|
|
|
|
{text: 'Cancel', onPress: () => console.log('Cancel Pressed!')},
|
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
|
|
|
]
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with two buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
null,
|
|
|
|
[
|
|
|
|
{text: 'Foo', onPress: () => console.log('Foo Pressed!')},
|
|
|
|
{text: 'Bar', onPress: () => console.log('Bar Pressed!')},
|
|
|
|
{text: 'Baz', onPress: () => console.log('Baz Pressed!')},
|
|
|
|
]
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with three buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Foo Title',
|
|
|
|
alertMessage,
|
|
|
|
'..............'.split('').map((dot, index) => ({
|
|
|
|
text: 'Button ' + index,
|
|
|
|
onPress: () => console.log('Pressed ' + index)
|
|
|
|
}))
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert with too many buttons</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2016-08-09 13:08:44 +00:00
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'Alert Title',
|
|
|
|
null,
|
|
|
|
[
|
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
cancelable: false
|
|
|
|
}
|
|
|
|
)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>Alert that cannot be dismissed</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2017-08-31 00:14:28 +00:00
|
|
|
<TouchableHighlight style={styles.wrapper}
|
|
|
|
onPress={() => Alert.alert(
|
|
|
|
'',
|
|
|
|
alertMessage,
|
|
|
|
[
|
|
|
|
{text: 'OK', onPress: () => console.log('OK Pressed!')},
|
|
|
|
]
|
|
|
|
)}>
|
|
|
|
<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';
|
|
|
|
|
|
|
|
static description = 'Alerts display a concise and informative message ' +
|
|
|
|
'and prompt the user to make a decision.';
|
|
|
|
|
|
|
|
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
|
|
|
};
|