首页 > 解决方案 > 我无法显示 ActivityIndi​​cator

问题描述

所以这是我的代码:

const imageSource = autoData.imgSource ? autoData.imgSource : autoData.downloadURL;

return (
 <View style={styles.main}>
(!imageSource? <ActivityIndicator size="large" /> :
   <Image source={imageSource} style={styles.image} />
)
</View>

所以基本上我想显示那个微调器,如果我没有得到任何信息 Invariant Violation: Text strings must be rendered within a <Text> component.

标签: react-nativereact-hooks

解决方案


你试试braces

如果你的图片是uri,你应该如下使用它:

<Image
  source={{
    uri: 'https://facebook.github.io/react/logo-og.png',
  }}
  style={{ width: 400, height: 400 }}
/>

用法

const imageSource = autoData.imgSource ? autoData.imgSource : autoData.downloadURL;

return (
 <View style={styles.main}>
{!imageSource ? (<ActivityIndicator size="large" />) :
   (<Image source={{ uri:imageSource }} style={styles.image} />)
}
</View>

推荐阅读