从路由获取图像。

发布于 2025-02-11 00:11:03 字数 1450 浏览 1 评论 0原文

我正在尝试为小组成员制作个人资料屏幕。 我的想法是使用路由参数来制作四个屏幕的一个字体来设置所有信息,例如:

<TouchableOpacity style={styles.ident1} onPress={() => navigation.navigate('Profile', {
    Nome: 'Ângelo J. da Rosa', Resto: ['19 Anos', 'Cocal do Sul - SC'], Foto: '../../assets/angelo.jpeg'
    })}>
    <Text style={{ fontSize: 20,fontWeight: 'bold' }}>Angelo</Text>
</TouchableOpacity>

但是,当我尝试使用我从paramns(foto)获得的路径从文件夹中获取图像时,我会得到一个错误,不知道如何继续

我的屏幕字体:

import React from 'react';
import { View, Text, Image, StyleSheet } from 'react-native';

export default function Profile({ route, navigation }) {
    const { Nome, Resto, Foto } = route.params;

    return (
        <View style={styles.container}>

            <Image
                style={styles.image}
                source={require({Foto})}
            />
            <Text style={[styles.headline]}>{"\n"}{Nome}</Text>

            <View style={[styles.views, styles.ident1]}>,
                <Text style={[styles.desc]}>{Resto[0]}</Text>
                <Text style={[styles.desc]}>{Resto[1]}</Text>
                <Text style={[styles.desc]}>{Resto[2]}</Text>
                <Text style={[styles.desc]}>{Resto[3]}</Text>
                <Text style={[styles.desc]}>{Resto[4]}</Text>
             </View>
        </View>
    )
};

I'm trying to make a profiles screen for my members of the group.
My idea is make just one font for the four screen using route params to set all informations, like this:

<TouchableOpacity style={styles.ident1} onPress={() => navigation.navigate('Profile', {
    Nome: 'Ângelo J. da Rosa', Resto: ['19 Anos', 'Cocal do Sul - SC'], Foto: '../../assets/angelo.jpeg'
    })}>
    <Text style={{ fontSize: 20,fontWeight: 'bold' }}>Angelo</Text>
</TouchableOpacity>

But when I am trying to get the image from the folder using the path that I got from the paramns (Foto), i get an error and not know how to proceed

My screen font:

import React from 'react';
import { View, Text, Image, StyleSheet } from 'react-native';

export default function Profile({ route, navigation }) {
    const { Nome, Resto, Foto } = route.params;

    return (
        <View style={styles.container}>

            <Image
                style={styles.image}
                source={require({Foto})}
            />
            <Text style={[styles.headline]}>{"\n"}{Nome}</Text>

            <View style={[styles.views, styles.ident1]}>,
                <Text style={[styles.desc]}>{Resto[0]}</Text>
                <Text style={[styles.desc]}>{Resto[1]}</Text>
                <Text style={[styles.desc]}>{Resto[2]}</Text>
                <Text style={[styles.desc]}>{Resto[3]}</Text>
                <Text style={[styles.desc]}>{Resto[4]}</Text>
             </View>
        </View>
    )
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2025-02-18 00:11:03

通过图像路径时,您正在犯一个错误。您可以按照以下代码进行操作:

    Foto: require('../../assets/angelo.jpeg')
            

并将其用作这样的道具:

<Image source={Foto}/>

注意:有关更多信息,请参考以下信息:载荷图像随着道具的反应天然

You are doing one mistake while passing the image path. You can follow the below code:

    Foto: require('../../assets/angelo.jpeg')
            

And use it as a prop like this :

<Image source={Foto}/>

NOTE: For more information please refer this: Load image passed as props react native

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文