AlertIOS组件应用很广,静态方法有两个
1、alert(title,message,buttons) 普通对话框,其中buttons是对象数组.
2、prompt(title,value,buttons):提供输入的对话框,其中buttons是对象数组。
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
AlertIOS,
} from 'react-native';
var Alert=React.createClass({
render() {
return (
<View style={styles.container}>
<Text style={styles.textStyle} onPress={this.clickAlert()}>点击AlertIOS.alert</Text>
<Text style={styles.textStyle} onPress={this.clickPromprt()}>点击AlertIOS.promprt</Text>
</View>
);
},
//AlertIOS.alert点击
clickAlert(){
AlertIOS.alert('提示','React Native',[{text:'取消', onPress:()=>console.log('点击了取消')}
,{text:'确认', onPress:()=>console.log('点击了确认')},])
},
// AlertIOS.promprt点击
clickPromprt(){
AlertIOS.prompt('提示','请输入相关信息',[{text:'取消',onPress:()=>console.log('点击了取消')},
{text:'确认',onPress:(e)=>console.log(e)}])
},
})
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
textStyle:{
height:50,
}
});