react-native - 在获取数据之前,如何在本机反应中使用 activityIndicator?
问题描述
我无法加载activityIndicator
直到我的数据被提取
if(loanAmount == undefined) {
return (
<View style={styles.indicatorContainer}>
<ActivityIndicator size="large" color={ZW_BUTTON_COLOR} />
</View>
);
}
else{
return (
<View style={styles.container}>
<View style={styles.repaymentDialog}>
<View style={styles.imageContainer}>
<ZWListItemAvatar borrowerObj={selectedBorrower} onPress={this.onShowProfile} />
<LabelText style={styles.labelDialogName} fontSize={16} >
{defaultName}
</LabelText>
</View>
<View style={styles.inputContainer}>
<LabelText style={styles.labelDialogTitle} fontSize={16}>
{loanState === LOAN_REQUEST_SUBMITTED ?
t('repayment-dialog.fee-due') :
t('repayment-dialog.amount-repaid')}
</LabelText>
<View style={styles.inputSubContainer}>
<ZWNumericInput
defaultValue={defaultValue}
textAlign="right"
onChangeText={this.changeRepayment}
/>
<LabelText style={[styles.labelDialogTitle, { alignSelf: 'center' }]} fontSize={16}>
{t('repayment-dialog.kyat')}
</LabelText>
</View>
<LabelText style={styles.labelDialogPaid} fontSize={16}>
Already repaid today {defaultPaid}
</LabelText>
{loanState !== LOAN_REQUEST_SUBMITTED &&
<LabelText style={styles.labelDescription} fontSize={14}>
{dayLate} payments missed
</LabelText>
}
<LabelText style={styles.loanContainer} fontSize={16} >
LOAN: {loan}
</LabelText>
<LabelText style={styles.loanContainer} fontSize={16} >
LOAN AMOUNT: {loanAmount}
</LabelText>
{/* <Button title="done" onPress={()=> alert('done')}/>*/}
</View>
<View style={styles.actionContainer} >
<TouchableOpacity style={styles.buttonCancel} onPress={onCancel}>
<LabelText style={styles.labelCancel} fontSize={13}>
{t('repayment-dialog.cancel')}
</LabelText>
</TouchableOpacity>
<TouchableOpacity
style={styles.buttonOK}
onPress={() => onOK(this.state.repaymentAmount)}
>
<LabelText style={styles.labelOK} fontSize={13}>
{t('repayment-dialog.ok')}
</LabelText>
</TouchableOpacity>
</View>
</View>
</View>
);
解决方案
Please follow below code for Indicator.
import React, { Component } from 'react'
import {
ActivityIndicator,
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native'
export default class App extends Component {
render() {
return (
<View style={[styles.yourStyle]}>
{this.state.isProgress && <ActivityIndicator size="large" color="#0000ff" />}
<your other stuff....>
</View>
)
}
}
You can also used this into HOC(Higher order component) and use as a generic for all over project. Hope it helps you.
推荐阅读
- python - Python 3.8.6 中的 ImportError
- compiler-errors - 在 C++ 中定义和使用 std::map 时出现编译错误
- c++ - 字符串擦除函数导致堆损坏
- swiftui - 更改焦点上 TextField 的样式(每个字段没有变量)
- python - 卡在这个问题中,无法理解子数组和的代码
- javascript - 为什么我的 Javascript 画布图像不移动我看不到错误
- python - 使用 python 在 .json 文件中存储数据的所有不同方法是什么?
- axios - 如何从 axios 请求中获取数据?
- python - Discord.py 频道和公会检测问题
- ruby-on-rails - 让应用程序中的所有方法在 Rails 控制台中可用的快速方法?