React native Model组件的使用
来源:互联网 发布:淘宝编辑图片软件 编辑:程序博客网 时间:2024/06/07 01:37
1、Model的介绍
从官方文档可以知道,Modal组件可以用来覆盖包含React Native根视图的原生视图(如UIViewController,Activity)。其实model就是一个遮盖层,可以遮盖iOS的UIViewController,也可以遮盖Android的activity。如编写各种dialog。
2、Model的使用
用Model写一个加载的loading
import React,{Component,PropTypes} from 'react';import {View,Text,Platform,TouchableHighlight,ActivityIndicator,Modal} from 'react-native';// import Modal from 'react-native-root-modal';class Loading extends Component { constructor(props) { super(props); this.state = { modalVisible: !this.props.hudHidden, hudText:!this.props.hudText, } } close() { // alert('关闭') if (Platform.OS === 'android') { setTimeout(()=>{ this.setState({modalVisible: false}); },1000) }else { this.setState({modalVisible: false}); } } show(textStr) { this.setState({modalVisible: true,hudText:textStr}); } render() { if (!this.state.modalVisible) { return null } return ( <Modal animationType={"none"} transparent={true} visible={this.state.modalVisible} onRequestClose={() => {}} > <View style={{flex: 1,alignItems:'center',justifyContent:'center'}}> <View style={{borderRadius: 10,backgroundColor:'rgba(0,0,0,0.5)',width:100,height:100,alignItems:'center'}}> <ActivityIndicator animating={true} color = 'white' style={{ marginTop:20, width: 60, height: 60, }} size="large" /> <Text allowFontScaling={false} style={{fontSize:15,color: 'white'}}>{this.state.hudText}</Text> </View> </View> </Modal> ); }}Loading.PropTypes = { hudHidden: PropTypes.bool.isRequired, hudText: PropTypes.string,}export default Loading;
这个loading中有两个方法show()和close().
在代码中引用这个loading
import React, { Component } from 'react';import { StyleSheet, Text, View, Image, TouchableOpacity, Dimensions, Platform, Alert, ToastAndroid, TextInput, ListView, ActivityIndicator, NativeModules, ScrollView, Keyboard,} from 'react-native';//导航import Loading from './loading';class SatisfactionSurvey extends Component { constructor(props) { super(props) this.state = { } } render() { return( 。。。。。。 <Loading ref={r=>{this.Loading = r}} hudHidden = {true} hudText = {''}></Loading>//放在布局的最后即可 ); }}module.exports = SatisfactionSurvey;
在需要显示的地方调用this.Loading.show();
,在需要隐藏的地方调用this.Loading.close();
阅读全文
1 0
- React native Model组件的使用
- React Native 之组件react-native-sound的使用
- react-native图片组件的使用
- React Native 的 Navigator 组件使用方式
- React Native 的 Navigator 组件使用方式
- React Native中组件的封装使用
- React-Native中导航组件react-navigation的使用
- React Native使用原生组件
- react-native组件的生命周期
- React Native 组件的生命周期
- React Native-组件的引用
- React Native组件的生命周期
- React Native组件的生命周期
- react-native组件的生命周期
- React Native的组件ListView
- React Native 组件的生命周期
- React Native-组件的引用
- React Native 简单的组件
- 4种PHP异步执行的常用方式
- FastJSON、Gson和Jackson性能对比和共同缺点,注意事项
- 蓝桥杯练习----入门训练 圆的面积
- main-bower-files <gulp插件>
- win10 下 c++遍历文件夹
- React native Model组件的使用
- File类
- PHP设计模式之装饰模式
- 用eclipse在maven里面下jar
- Xcode快捷键编辑
- ros kinect设备 gmapping 出现"No matching device found" 错误
- 2017noip总结
- 我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。
- 绕过沙箱