日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號(hào) > 充電吧
[導(dǎo)讀]我們經(jīng)常需要執(zhí)行耗時(shí)較長的代碼。為了良好的用戶體驗(yàn),我們?cè)诋惒教幚砗臅r(shí)代碼時(shí),采用Loading加載動(dòng)畫的形式來等待處理。這里參考了《React native Model組件的使用》。1.在compo

我們經(jīng)常需要執(zhí)行耗時(shí)較長的代碼。為了良好的用戶體驗(yàn),我們?cè)诋惒教幚砗臅r(shí)代碼時(shí),采用Loading加載動(dòng)畫的形式來等待處理。

這里參考了《React native Model組件的使用》。


1.在components下新建loading.js文件,如下

/**
?*?調(diào)用說明:
?*{this.Loading?=?r}}?hide?=?{true}?/>?//放在布局的最后即可
?*?在需要顯示的地方調(diào)用this.Loading.show();
?*?在需要隱藏的地方調(diào)用this.Loading.close();
?*/

import?React,?{?Component?}?from?'react';
import?{
????Platform,
????View,
????ActivityIndicator,
????Modal,
}?from?'react-native';

import?PropTypes?from?'prop-types';

export?default?class?Loading?extends?Component?{
????constructor(props)?{
????????super(props);
????????this.state?=?{
????????????modalVisible:?!this.props.hide,
????????}
????}

????close()?{
????????if?(Platform.OS?===?'android')?{
????????????setTimeout(()=>{
????????????????this.setState({modalVisible:?false});
????????????},1000)
????????}else?{
????????????this.setState({modalVisible:?false});
????????}
????}

????show()?{
????????this.setState({modalVisible:?true});
????}

????render()?{
????????if?(!this.state.modalVisible)?{
????????????return?null
????????}
????????return?({}}
????????????>);
????}
}

Loading.PropTypes?=?{
????hide:?PropTypes.bool.isRequired,
};

2.在App.js中引入loading.js

import?Loading?from?'./components/loading';

在最外層的View中底部渲染Loading

????????????{/*{/*......*/}
????????????????{/**/}
????????????????{/**/}{this.Loading?=?r}}?hide?=?{true}?/>

定義全局的方法

let?self;?//將App組件中的this賦給全局的self
global.showLoading?=?false;?//所有子頁面均可直接調(diào)用global.showLoading()來展示Loading
global.closeLoading?=?false;?//所有子頁面均可直接調(diào)用global.closeLoading()來關(guān)閉Loading

給全局方法賦值,使其可以在任何頁面調(diào)用

????componentDidMount()?{
????????self?=?this;
????????global.showLoading?=?function()?{
????????????self.Loading.show();
????????};
????????global.closeLoading?=?function()?{
????????????self.Loading.close();
????????};
????}

調(diào)用Loading

????_showLoading()?{
????????global.showLoading();
????????setTimeout(()=>{
????????????global.closeLoading();
????????},500)
????}
this._showLoading();


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉