从路由获取图像。
我正在尝试为小组成员制作个人资料屏幕。 我的想法是使用路由参数来制作四个屏幕的一个字体来设置所有信息,例如:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过图像路径时,您正在犯一个错误。您可以按照以下代码进行操作:
并将其用作这样的道具:
注意:有关更多信息,请参考以下信息:载荷图像随着道具的反应天然
You are doing one mistake while passing the image path. You can follow the below code:
And use it as a prop like this :
NOTE: For more information please refer this: Load image passed as props react native