示例
import React, { Component } from 'react';
import {View,AlertIOS,StyleSheet,Button } from 'react-native';
export class pageComponent extends Component {
constructor(props){
super(props);
this.state={
value: 10
}
}
componentDidMount() {
}
alert=()=>{
AlertIOS.alert(
'标题',
'内容'
);
}
prompt=()=>{
AlertIOS.prompt(
"请输入密码",
"请输入你的密码支付20元",
[
{
text: "取消",
onPress: () => console.log("取消支付"),
style: "cancel"
},
{
text: "确认",
onPress: password => console.log("确认支付: " + password)
}
],
"secure-text"
);
}
prompt2=()=>{
AlertIOS.prompt(
"更新昵称",
null,
text => console.log("你的昵称是 " + text),
null,
"default"
);
}
render(){
return(
<View style={styles.container}>
<Button
style={styles.text}
onPress = {
this.alert
}
title = {'弹出一个 iOS 提示框'}
/>
<Button
style={styles.text}
onPress = {
this.prompt
}
title = {'弹出一个带输入框的 iOS 提示框'}
/>
<Button
style={styles.text}
onPress = {
this.prompt2
}
title = {'具有默认按钮和自定义回调'}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
marginTop: 100,
padding: 10,
borderRadius: 5,
alignItems: 'center',
width: 300
},
text: {
marginTop: 20,
fontSize:20,
}
});