【问题标题】:Image is not display only image area showing firebase React Native图像不只显示显示firebase React Native的图像区域
【发布时间】:2022-01-02 12:59:26
【问题描述】:

我正在从 Firestore 中检索图像,但它在图像区域中显示了这一点。我无法解决这个问题。

方法:

useLayoutEffect(() => {
    const unsubscribeimage = db
        .collection("token")
     
        .onSnapshot((snapshot) =>
            setPhoto(
                snapshot.docs.map((doc) => ({
                    id: doc.id,                
                    dataimg: doc.data(),
                    
                    
                }))
            

            )

        );
    return unsubscribeimage;
    

    
}, []);

我的返回码:

 <View { photo.map(({dataimg,id }) =>
            
            <View  style={styles.sender} key={id}>
            <Avatar source={{uri: dataimg}} style={{ width: 200, height: 200 }}  />
            </View>

我正在获取这张图片:

【问题讨论】:

  • doc.data() 不会返回字符串,而是返回具有imageURL 属性的对象。 Avatar 在其 source 属性中期望什么?
  • 好的,我怎样才能在源代码中显示图像?头像就是图片标签,我只想展示图片。
  • 阿凡达是否期望其source 属性的字符串?如果是这样,那么它将是source={dataimg.imageURL}。它是否期望具有uri 属性的对象是一个字符串?如果是这样,那么它将是source={{ uri: dataimg.imageURL }}。如有其他请提供头像相关代码。
  • 是的 Avatar 可以接受 oject。谢谢你的工作你让我的一天新年快乐
  • @NicholasTower 感谢您的帮助。 ???想把它写下来作为答案,这样我们就可以结束这个问题了吗?

标签: reactjs firebase react-native google-cloud-firestore


【解决方案1】:
dataimg: doc.data()

doc.data() 将返回整个文档对象,在本例中如下所示:

{
  imageURL: "https://**etc*",
}

所以稍后当您执行source={{uri: dataimg}} 时,uri 是整个对象,而不仅仅是 uri。相反,您需要执行source={{uri: dataimg.imageURL}}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-14
  • 2023-01-31
  • 2020-02-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多