I don't understand why this code doesn't work.
const UserCard = props => {
return (
<View style={styles.card}>
<View style={{flex: 0.33}}>
<Image source={require(props.user.image)} style={{width: 100, height: 100}}/>
</View>
<View style={{flex: 0.66}}>
<Text>bb</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
card: {
flexDirection: 'row',
backgroundColor: 'green'
},
});
export default UserCard;
props.user.image = 'Assets/test/joan.jpg'
If I put in an image:
<Image source={require('Assets/test/joan.jpg')} style={{width: 100, height: 100}}/>
It's works.
In assets I have package.json with name Assets so I can use absolute paths.
I have test various options and none of them.
For example:
return (
const user_image = require(props.user.image);
...
<Image source={user_image} style={{width: 100, height: 100}}/>
...
Other:
return (
const user_image = props.user.image;
...
<Image source={require(user_image)} style={{width: 100, height: 100}}/>
...
Or with src instead of source, but it doesn't work...
Also I test it changing
const UserCard = props => {
For
class UserCard extends React.Component {
And still the same...
Please help.
EDIT:
HomeScreen with object users
const users = [
{
"image" : "Assets/test/fernando.jpg",
"name" : "Fernando",
"description" : "General Manager",
},
{
"image" : "Assets/test/daniel.jpg",
"name" : "Daniel",
"description" : "CEO",
},
{
"image" : "Assets/test/joan.jpg",
"name" : "Joan",
"description" : "Manager",
},
];
class HomeScreen extends React.Component {
...
render() {
return (
<SafeAreaView style={styles.container}>
<ScrollView
style={styles.container}
contentContainerStyle={styles.contentContainer}>
{ typeof users === 'object' && users.length > 0 && (users.map((user, index) => {
return (
<View key={index} style={{flex: 1, backgroundColor: 'red'}}>
<UserCard user={user} />
</View>
)})
) }
</ScrollView>
</SafeAreaView>
);
}