I have defined a React Native class that is designed to fill a "tableView" cell with an image reference that is a prop input to the class. This is invoked with the use of FlatList. However, this class is unable to find the input image reference in the bundle when specified using an Image source tag. It can only be found if it is a hard coded reference.
The class is defined as follows:
class ListItem extends React.PureComponent {
_onPress = () => {
this.props.onPressItem(this.props.index);
}
render() {
const item = this.props.item;
console.log("ChannelSelection Mix Button artwork: ", item.artwork);
return (
<TouchableHighlight
onPress={this._onPress}
underlayColor="transparent">
<View>
<View style={styles.rowContainer}>
<Image source={{ uri: item.artwork }} style={styles.buttonContainer} />
<View style={styles.mixButtonTitleContainer}>
<Text style={styles.mixButtonTitle}
numberOfLines={2}>{item.channelTitle}</Text>
</View>
</View>
</View>
</TouchableHighlight>
);
}
}
When this class in invoked, I get a warning that says:
Warning
Could not find image file:///Users/myname/Library/Developer/CoreSimulator/Devices/34AE8A68-E69D-4804-B3C4-96DE7A051B9B/data/Containers/Bundle/Application/C79368E9-3D1B-492C-B72B-9BF5C4D3262B/myApp.app/./Resources/MissingAlbumArt.png
The console output to print item.artwork is:
'ChannelSelection Mix Button artwork: ', './Resources/MissingAlbumArt.png'
so you can see that the name of the file is being passed in correctly.
Note that if I change the line:
<Image source={{ uri: item.artwork }} style={styles.buttonContainer} />
to:
<Image source={require('./Resources/MissingAlbumArt.png')} style={styles.buttonContainer} />
then the error goes away.
So, how can I properly reference the .png files in my Resources directory? And why are my .png files not in the Resources directory of my bundle?