react native Alert AlertIOS 使用详解

来源:互联网 发布:淘宝卖文具赚钱吗 编辑:程序博客网 时间:2024/06/10 08:47

Alert:提示对话框,只有1个方法:

static alert(title: ?string,message?: ?string,buttons?: Buttons,options?: Options,type?: AlertType,)

  • title:标题
  • message:内容
  • buttons:按钮数组
  • options(android):其余参数,只有一个参数 cancelable。
  • type:过期,可以使用AlertIOS.prompt()替代。
/** * Created by  on 2017/5/24. */import React, {Component} from 'react';import {    StyleSheet,    View,    Button,    Alert,} from 'react-native';export default class AlertDemo extends Component {    static navigationOptions = {        title: 'Alert'    }    _alert = () => {        // Alert.alert('title');        // Alert.alert('title','Message');        Alert.alert('Alert Title', 'Alert  Message',            [                {                    text: '稍后再说', onPress: () => {                    Alert.alert('', '点击了稍后再说')                }                },                {                    text: '取消', style: 'cancel', onPress: () => {                    Alert.alert('', '点击了取消')                },                },                {                    text: '确定', onPress: () => {                    Alert.alert('', '点击了确定')                }                },                {                    text: '确定1', onPress: () => {                    Alert.alert('', '点击了确定')                }                },            ],            {cancelable: false},        );    }    render() {        return (            <View style={{flex:1}}>                <Button title='Alert' onPress={this._alert}/>            </View>        );    }}

这里写图片描述

github下载地址