I'm trying to make a basic React Native app where on the main page a person's picture will be displayed and on clicking that a new View will open and have all the details of that particular person. I'm able to print the name of the person but can't get to display his image, which is saved by the name of the person itself. Example - If the name is XYZ, image name is XYZ.jpg
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, ScrollView, Button, TouchableWithoutFeedback} from 'react-native';
import { createStackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
return (
<View style={styles.container}>
<ScrollView vertical={true} contentContainerStyle={{flexGrow: 1}}>
<ScrollView horizontal={true}>
<TouchableWithoutFeedback title="Go to Details" onPress={() => {
this.props.navigation.navigate('Details', {
name: 'Rohit',
otherParam: 'anything you want here',
});
}}>
<View style={styles.view}>
<Image source={require('./assets/rohit.jpg')} style={styles.image}></Image>
<Text style={styles.text}>Rohit</Text>
</View>
</TouchableWithoutFeedback>
</ScrollView>
</View>
)
}
}
class DetailsScreen extends React.Component {
render() {
const { navigation } = this.props;
const name = navigation.getParam('name', 'NO-ID');
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
----HERE---> <Image source={require('./assets/'+{name}+'.jpg')} style={styles.image}></Image>
<Text>{name}</Text>
</View>
);
}
}
