【问题标题】:I am unable to display an ActivityIndicator我无法显示 ActivityIndi​​cator
【发布时间】:2019-08-20 08:57:01
【问题描述】:

这是我的代码:

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 &lt;Text&gt; component.

【问题讨论】:

    标签: react-native react-hooks


    【解决方案1】:

    你试试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>
    

    【讨论】:

    • 现在只有最后一件事.. 一个是 URI,一个是 imgSource .. 所以使用 {uri: imageSource} 仅在图像来自 downloadURL 时才有效。我还需要显示新选择的图像
    • 你的意思是你看不到图片?请看我修改后的答案。
    【解决方案2】:

    我认为问题与图像组件有关,

    请尝试以下,

    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>
    

    只有当 'imageSource' 是一个 uri/url 或像上面那样直接使用时,这才有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      相关资源
      最近更新 更多