Require Image dynamically in React Native

Viewed 2318

The documentation of React native (0.21) states, that it is only possible, to load pictures statically, i.e. if the file name is somehow known in advance:

Note that in order for this to work, the image name in require has to be known statically.

Source: https://facebook.github.io/react-native/docs/images.html#content

An example is given:

// GOOD
<Image source={require('./my-icon.png')} />

// BAD
var icon = this.props.active ? 'my-icon-active' : 'my-icon-inactive';
<Image source={require('./' + icon + '.png')} />

Unfortunately, in my case, I do not know the file names of the pictures in advance, as they are configured in a JSON file.

Is there a way to use local image files within react native? I could load them via the file:// protocol, if I knew the location of the files? Is there a constant or variable for he location of the app within the iOS file system?

1 Answers
Related