2015-12-17 19:09:22 +00:00
|
|
|
/**
|
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
Alert,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
|
|
|
} = React;
|
|
|
|
|
|
|
|
var UIExplorerBlock = require('./UIExplorerBlock');
|
|
|
|
|
|
|
|
// corporate ipsum > lorem ipsum
|
|
|
|
var alertMessage = 'Credibly reintermediate next-generation potentialities after goal-oriented ' +
|
|
|
|
'catalysts for change. Dynamically revolutionize.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple alert examples.
|
|
|
|
*/
|
|
|
|
var SimpleAlertExampleBlock = React.createClass({
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
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>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
var AlertExample = React.createClass({
|
|
|
|
statics: {
|
|
|
|
title: 'Alert',
|
|
|
|
description: 'Alerts display a concise and informative message ' +
|
|
|
|
'and prompt the user to make a decision.',
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<UIExplorerBlock title={'Alert'}>
|
|
|
|
<SimpleAlertExampleBlock />
|
|
|
|
</UIExplorerBlock>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
};
|