React Native之Modal组件实现遮罩层效果
2017-07-12 22:21
766 查看
React-Native中Modal的使用
/** * React Native App * dongtao 2017/04/22 * @flow */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, Modal, PixelRatio, View } from 'react-native'; class ModalDemo extends Component { constructor(props) { super(props);//这一句不能省略,照抄即可 this.state = { animationType: 'none',//none slide fade modalVisible: false,//模态场景是否可见 transparent: true,//是否透明显示 }; } render() { let modalBackgroundStyle = { backgroundColor: this.state.transparent ? 'rgba(0, 0, 0, 0.5)' : 'red', }; let innerContainerTransparentStyle = this.state.transparent ? { backgroundColor: '#fff', padding: 20 } : null; return ( <View style={{ alignItems: 'center', flex: 1 }}> <Modal animationType={this.state.animationType} transparent={this.state.transparent} visible={this.state.modalVisible} onRequestClose={() => { this._setModalVisible(false) } } onShow={this.startShow} > <View style={[styles.container, modalBackgroundStyle]}> <View style={[styles.innerContainer, innerContainerTransparentStyle]}> <Text style={styles.date}>2016-08-11</Text> <View style={styles.row}> <View > <Text style={styles.station}>长沙站</Text> <Text style={styles.mp10}>8: 00出发</Text> </View> <View> <View style={styles.at}></View> <Text style={[styles.mp10, { textAlign: 'center' }]}>G888</Text> </View> <View > <Text style={[styles.station, { textAlign: 'right' }]}>北京站</Text> <Text style={[styles.mp10, { textAlign: 'right' }]}>18: 00抵达</Text> </View> </View> <View style={styles.mp10}> <Text>票价:¥600.00元</Text> <Text>乘车人:东方耀</Text> <Text>长沙站 火车南站 网售</Text> </View> <View style={[styles.mp10, styles.btn, { alignItems: 'center' }]}> <Text style={styles.btn_text}>去支付</Text> </View> <Text onPress={this._setModalVisible.bind(this,false) } style={{fontSize:20,marginTop:10}}> 关闭 </Text> </View> </View> </Modal> <Text style={{ fontSize: 30,color:'red' }} onPress={this._setModalVisible.bind(this, true) }>预定火车票</Text> </View> ); } _setModalVisible = (visible) => { this.setState({ modalVisible: visible }); } startShow=()=>{ alert('开始显示了'); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 40, }, innerContainer: { borderRadius: 10, alignItems: 'center', }, row: { alignItems: 'center', flex: 1, flexDirection: 'row', marginBottom: 20, }, rowTitle: { flex: 1, fontWeight: 'bold', }, button: { borderRadius: 5, flex: 1, height: 44, alignSelf: 'stretch', justifyContent: 'center', overflow: 'hidden', }, buttonText: { fontSize: 18, margin: 5, textAlign: 'center', }, page: { flex: 1, position: 'absolute', bottom: 0, left: 0, right: 0, top: 0, }, zhifu: { height: 150, }, flex: { flex: 1, }, at: { borderWidth: 1 / PixelRatio.get(), width: 80, marginLeft:10, marginRight:10, borderColor: '#18B7FF', height: 1, marginTop: 10 }, date: { textAlign: 'center', marginBottom: 5 }, station: { fontSize: 20 }, mp10: { marginTop: 5, }, btn: { width: 60, height: 30, borderRadius: 3, backgroundColor: '#FFBA27', padding: 5, }, btn_text: { lineHeight: 18, textAlign: 'center', color: '#fff', }, }); AppRegistry.registerComponent('ModalDemo', () => ModalDemo);
1.png
相关文章推荐
- React Native之Modal组件实现遮罩层效果
- React-Native学习笔记之:Modal实现覆盖效果(类似安卓中PopuWindow)
- React Native View 组件通过阴影渲染实现组件浮现效果
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- react-native DatePicker日期选择组件的实现
- React Native 实现类似QQ的侧滑列表效果
- React Native 的图片点击放大效果的组件使用 react-native-zoom-image
- 实现点击在组件下方弹出单选框。并且选中哪个哪个后方显示对勾。文字变色。同时展示Popupwindow实现和遮罩效果
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- React Native之ViewPagerAndroid仿淘宝首页顶部分类布局效果实现
- ReactNative 中 ListView实现GridView效果
- React-Native应用ListView实现上拉下拉刷新效果实践
- React Native之Modal实现自定义Dialog
- React Native自定义标题栏组件的实现方法
- EasyUI实现tabs组件IFrame模式的遮罩效果
- React Native之ViewPagerAndroid仿淘宝首页顶部分类布局效果实现
- 使用react-native-pull实现跨平台Android&IOS下拉刷新滑动回弹效果
- 《React-Native系列》23、 js实现下拉刷新效果(Android和iOS通用)
- 这是一个实现下拉刷新的react native组件 react-native-pullview
- React Native之ListView实现九宫格效果