Im trying to get a more dynamic way of showing articles. I made a JSON file which contains all the info and loop over it and for each item it creates an item on the homepage. This is working and the title and text ar shown. Now im having trouble with the images. I dont get any errors so i think i might have to do with the path im calling in the json file.
project structure:
src
--articles
----img
------img.jpg
----articlePreview.js
----articles.json
----fullArticle.js
--homepage
----index.js
App.js
Testing json, as you can see i tried some different paths and tried some more as well:
{
"articles": [
{
"title": "Test",
"imageName": "/img/img.jpg",
"text": "more text to test"
},
{
"title": "Test22",
"imageName": "./img/img.jpg",
"text": "more text to test"
}
]
}
On the homepage i map all the items in the json file like this:
const contents = json.articles.map(function (item) {
return (
<ArticleHome title={item.title} text={item.text} image={item.imageName} />
);
});
and finally the component which should display them:
function ArticleHome({title, text, imageName}) {
return (
<View>
<Card>
<CardItem header bordered>
<Body>
<Image
style={{ width: '100%', height: 400 }}
source={{uri: imageName}}
/>
<Text>
{title}
</Text>
<Text>
{text.substring(0,240)}...
</Text>
<Button
title="Lees Meer"
color="#d10a10"
onPress={() => RootNavigation.navigate('Article')}
/>
</Body>
</CardItem>
</Card>
</View>
);
}