user3352382
user3352382

Reputation: 353

Image non displaying in React Native application: URI source with local path

I am trying to show an image inside a React Native app, but I am experiencing some issues. Considering that the runtime value of this.state.icon is './icons/Icon.png', I can't figure out why the first line of code doesn't work (an empty blank space is shown instead of the image), while the second version works properly.

<Image style={styles.Icon} source={this.state.icon} />

<Image style={styles.Icon} source={require('./icons/Icon.png')} />

This kind of solution doesn't work too: source={{uri: './icons/Icon.png'}}

Upvotes: 1

Views: 674

Answers (1)

agenthunt
agenthunt

Reputation: 8678

require does not support dynamic loading of modules. Javascript files are statically analysed. See Similar issue athttps://github.com/facebook/react-native/issues/2481

Upvotes: 1

Related Questions