0

返回 renderRow 时,我遇到了 Image Background 组件的问题。

    import back1 from '../../assets/back1.jpg';

    renderRowpost = ({ item }) => {
        return ( 
                MORECONTENT....     
                {item.imgfondo ?  //IF EXIST BACK IMAGEN
                    <View key={"viwid_" + item.postid} style={styles.warptextopost}>
                        <ImageBackground source={back1}>
                            <Text key={"text_id" + item.postid} style={styles.stylpublictext} >{item.posttexto}</Text>
                        </ImageBackground>
                    </View>
                    : //as there is no image I place the text without background
                    <View key={"viwid_" + item.postid} style={styles.warptextopost}>
                         <Text key={"text_id" + item.postid} style={styles.stylpublictext} >{item.posttexto}</Text>
                    </View>
                }       
   )
   }


          //Where I show all the content I get from RenderrenderRowpost

                <FlatList
                    data={this.state.datapost}
                    renderItem={this.renderRowpost}
                    keyExtractor={(item, index) => index.toString()}
                />

我收到以下错误:不变违规:元素类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。,但是如果我删除 ImageBackground 组件或放置一个 Image 组件(里面没有文本),如果它显示正常内容,它只会在放置 ImageBackground 组件时给我错误,有什么解决方案吗?我需要在视图中放置一个背景图像及其各自的文本,非常感谢..

4

1 回答 1

1

加载图片如下

<ImageBackground source={require('../../assets/back1.jpg')}>
...
</ImageBackground>

我猜你不能像在导入中加载 js 模块那样导入图像。

于 2019-09-28T05:19:33.407 回答