【发布时间】:2021-12-20 23:51:44
【问题描述】:
在下面的这段代码中,我创建了 2 个选项卡,使用状态来跟踪哪个选项卡是可见的。
currentTab === 1 & currentTab === 2
我对两者都使用三元运算符。 对于第二个选项卡,如果数据正在加载,我会显示一个活动指示器,并在数据加载完美时消失。 但是,即使我没有在第一个三元运算符而是在第二个运算符中使用它,活动监视器也会(连续)显示在选项卡 1 上。有什么建议吗?
<ScrollView style={{flex: 1}}>
{this.state.currentTab === 1 ? (
<View style={{flex: 1}}>
<Avatar
marginLeft={20}
rounded
source={{uri: image}}
/>
</View>
) : null}
{this.state.currentTab === 2 &&
this.state.metadata != null ? (
<View style={{flex: 1, paddingBottom: 20}}>
<Text style={styles.sectionHeader}> History</Text>
</View>
) : (
<ActivityIndicator size="large" />
)}
</ScrollView>
【问题讨论】:
标签: react-native conditional-operator uiactivityindicatorview