Reputation: 2461
I have my image under
/app/assets/images/logo/logo.png
If I have a component under /app/components/headerbar/headerbar.js
it can't use <Image source={require('./app/assets/images/logo/logo.png')} style={styles.logo} />
because it says "module not found [..]"
However if I place my image under the same folder as the headerbar.js
file and change path to ./logo.png
then it works fine. Setting the path to ../app/assets/images/logo/logo.png
doesn't work either.
Do I have to have the static image under the same folder as the component for it to work in RN?
Upvotes: 0
Views: 117
Reputation: 13406
You have to reference the file like this: require('../../assets/images/logo/logo.png')
Alternatively put a js file in your app root and reference your assets in there, exporting them as consts:
export const LOGO = require('./assets/images/logo/logo.png');
Then you can simply import the const and write
<Image source={LOGO} style={styles.logo} />
Upvotes: 2