react-native弹窗Alert

前端之家收集整理的这篇文章主要介绍了react-native弹窗Alert前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

学习交流:https://gitee.com/potato512/Learn_ReactNative

react-native学习交流QQ群:806870562


效果


代码示例

import React from 'react';
import {View,Text,Button,Alert,AlertIOS} from "react-native";

const title = "温馨提示";
const message = '要下雨了,记得带伞'

export default class AlertPage extends React.Component {

  constructor(props) {
      super(props);
      _this = this;
      this.state = {
          inputText:'',};
  }

   render(){
     return(
       <View style={{marginTop:60,alignItems:"center"}}>
         <Text>Alert的使用</Text>
         <Button title="标题+确定" onPress={() => {
           Alert.alert(title)
         }}/>
         <Button title="标题+内容+确定" onPress={() => {
           Alert.alert(title,message)
         }}/>
         <Button title="标题+内容+取消+确定" onPress={() => {
           Alert.alert(
            title,message,[
              {text: '不带伞',onPress: () => console.log('Cancel Pressed'),style: 'cancel'},{text: '知道了',onPress: () => console.log('OK Pressed')},],)
         }}/>
         <Button title="标题+内容+多按钮" onPress={() => {
           Alert.alert(
            title,{text: '有人送伞',onPress: () => console.log('送伞')},{
              cancelable: true,onDismiss: () => {
                ToastAndroid.show('点击了外面',ToastAndroid.SHORT)
              }
            }
          )
         }}/>
         <Button title="iOS" onPress={() => {
           AlertIOS.alert(
             title,[
               {text: '取消',onPress: function() {console.log('取消按钮点击');}},{text: '确认',onPress: function() {console.log('确认按钮点击');}},]
           )
         }}/>
         <Button title="iOS+输入框" onPress={() => {
           AlertIOS.prompt(
             title,onPress: (text) => {
                 _this.setState({inputText:text})
                 console.log('你输入了: ' + _this.state.inputText)
               }},'secure-text',this.state.inputText,'number-pad'
           )
         }}/>

)

       </View>
     )
   }
}
原文链接:https://www.f2er.com/react/301426.html

猜你在找的React相关文章