React Native 弹出框
来源:互联网 发布:windows更新有必要吗 编辑:程序博客网 时间:2024/04/27 21:49
RN为我们提供了一个跨平台通用的Modal组件,我们可以用它来实现一个弹出框的视图。
先上效果图:
代码如下:
/** * Created by gyg on 2017/5/11. * 自定义弹出框组件 */'use strict'import React, {Component} from 'react';import { StyleSheet, View, Text, TouchableHighlight, Modal,}from 'react-native';export default class CustomModal extends Component { render() { return ( <Modal visible={this.props.visibility} transparent={true} animationType={'fade'}//none slide fade onRequestClose={()=>this.setState({visibility:false})} > <View style={styles.container}> <View style={styles.modalContainer}> <Text style={styles.modalTitle}>{this.props.title}</Text> <Text style={styles.modalMessage}>{this.props.message}</Text> <View style={styles.horizonLine}/> <View style={styles.row}> <TouchableHighlight style={styles.leftBn} onPress={this.props.onLeftPress} underlayColor={'#C5C5C5'}> <Text style={styles.leftBnText}>取消</Text> </TouchableHighlight> <View style={styles.verticalLine}/> <TouchableHighlight style={styles.rightBn} onPress={this.props.onRightPress} underlayColor={'#C5C5C5'} > <Text style={styles.rightBnText}>确定</Text> </TouchableHighlight> </View> </View> </View> </Modal> ) }}const styles = StyleSheet.create({ container:{ flex:1, backgroundColor:'rgba(0, 0, 0, 0.5)', justifyContent:'center', alignItems:'center' }, modalContainer: { marginLeft: 20, marginRight: 20, borderRadius: 3, backgroundColor: "white", alignItems:'center', }, modalTitle: { color: '#000000', fontSize: 16, marginTop: 10, }, modalMessage:{ color:'#8a8a8a', fontSize:14, margin:10, }, row:{ flexDirection:'row', alignItems:'center', }, horizonLine:{ backgroundColor:'#9f9fa3', height:0.5, alignSelf:'stretch' }, verticalLine:{ backgroundColor:'#9f9fa3', width:1, alignSelf:'stretch' }, leftBn:{ borderBottomLeftRadius:3, padding:7, flexGrow:1, justifyContent:'center', alignItems:'center', }, leftBnText:{ fontSize:16, color:'#8a8a8a', }, rightBn:{ borderBottomRightRadius:3, padding:7, flexGrow:1, justifyContent:'center', alignItems:'center', }, rightBnText:{ fontSize:16, color:'#00A9F2' }})
- visible bool 控制弹出框隐藏(false)或显示(true)
- transparent bool 控制弹出框背景,若为false则弹出框背景为灰色,会挡住弹出框后面的内容,true时才为modal根视图的背景颜色。
- animationType string 控制弹出框的动画效果 有三个值:none slide fade
- onRequestClose func 当请求关闭时执行
使用:
<CustomModal title="标题" message="消息" ref="_customModal" visibility={this.state.modalVisibility} onLeftPress={()=>{this.setState({modalVisibility:false})}} onRightPress={()=>{this.setState({modalVisibility:false})}}/>
源码
0 0
- React Native 弹出框
- React Native实现弹出选择框
- React-native 学习之Confirm弹出框
- React-native 学习之AlertDialog弹出框
- React-native 弹出Model
- react native 弹出编辑对话框
- react-native试玩(28)-弹出框API
- react native TextInput无法弹出输入框问题
- React Native自定义组件——弹出框
- react-native自定义对话框弹出框组件dialogs
- React Native API模块之Alert弹出框详解及使用
- 解决react-native软键盘弹出挡住输入框的问题
- React Native学习之Modal控件自定义弹出View
- React Native学习之Modal控件自定义弹出View
- React Native 应用在键盘弹出时优雅地响应
- React Native 应用在键盘弹出时优雅地响应
- react native
- React Native
- UE4 新手常用C++API
- Vue.js 计算属性
- qt之定时器 和随机数
- 中共中央组织部关于调整省以下国土资源主管部门干部管理体制的通知-组通字(2004)22号
- bzoj 2154 Crash的数字表格
- React Native 弹出框
- SAPUI5页面跳转方法
- phoenix适配cdh5.5.2安装
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 关于servlet的一些笔记
- Linux开发--多线程中的信号处理
- Spring的AOP获得方法的名字和参数
- 在线文档查看器GroupDocs.Viewer V17.4.0发布 | 支持DjVu格式
- linux前后台任务的切换以及执行暂停