The docs make it pretty clear that you cannot perform dynamic execution:
<Image source={require('./my-icon.png')} />
var icon = this.props.active ? 'my-icon-active' : 'my-icon-inactive';
<Image source={require('./' + icon + '.png')} />
var icon = this.props.active ? require('./my-icon-active.png') : require('./my-icon-inactive.png');
<Image source={icon} />
I have a use case that is not cut and dry that way, but I have a ListView and in the renderRow method I would like to make an image depending on some data in the specified row. For example, I want to do .. / img / 12.png by doing this
<Image style={styles.thumb} source={require("../img/12.png")} />
works fine however
let imagePath = "../img/" + row.number + ".png";
<Image style={styles.thumb} source={require(imagePath)} />
gives the following error:
Requiring unknown module "../img/12.png"
Is there any workaround here, it looks like it still ends up requiring the exact same line, it just doesn't work.
source
share