温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

React native 的弹出层组件使用

发布时间:2020-07-30 01:46:12 来源:网络 阅读:673 作者:jianngdeqin 栏目:移动开发

组件名称:Alert、AlertIOS  具体代码如下    

/*弹出层测试*/
import React,{Component} from 'react';
import {
  StyleSheet,
  View,
  Image,
  Text,
  TouchableOpacity,
  ScrollView,
  Navigator,
  Alert, //引入Alert组件
  TouchableHighlight,
  AlertIOS  //引入AlertIOS组件
} from 'react-native';
//创建一个组件
class CustomButton extends Component {
  render() {
    return (
      <TouchableHighlight    
        style={styles.button}
        underlayColor="red"   //触摸的时候颜色改变
        onPress={this.props.onPress}>  //当前触发时间
        <Text style={styles.buttonText}>{this.props.text}</Text>
      </TouchableHighlight>
    );
  }
}
//默认输出组件
export default class AlertDemo extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={{height:30,color:'black',margin:8}}>
          弹出框实例
        </Text>
        //触发事件
        <CustomButton text='点击弹出默认Alert'
          onPress={()=>Alert.alert('温馨提醒','确定退出吗?')}
          />
        <CustomButton text='点击弹出两个按钮的Alert'
          onPress={()=>Alert.alert('温馨提醒','确定退出吗?',[
            {text:'取消'},
            {text:'确定',}
            ])}
          />
        <CustomButton text='点击弹出三个按钮的Alert'
          onPress={()=>AlertIOS.alert('温馨提醒','确定退出吗?',[
            {text:'One'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            {text:'Two'},
            ])}
          />
          <CustomButton text='点击出现输入框'
            onPress={()=>AlertIOS.prompt('温馨提醒','确定退出吗?',[
              {text:'取消'},
              {text:'确定',}
              ])}
            />

      </View>
    );
  }
}



var styles = StyleSheet.create({
  container:{
    backgroundColor:"#fff",
    flex:1,
    marginTop:65,
},
button: {
  margin:5,
  backgroundColor: 'white',
  padding: 15,
  borderBottomWidth: StyleSheet.hairlineWidth,
  borderBottomColor: '#cdcdcd',
}


})


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI