Harvey
Harvey

Reputation: 1375

Cannot load image from Images.xcasset using React Native?

I'm learning React Native for IOS development. I followed the instruction below to load a image from Images.xcassets:

<Image source={require('image!house')}/>

Then I got this error: Unable to resolve module image!house from **/ProjectName/index.ios.js: Module does not exist in the module map or in these directories: **/ProjectName/node_modules

I found a solution from this : https://github.com/facebook/react-native/issues/282. But it doesn't seen to work

node_modules/react-native/packager/packager.sh --assetRoots=./ios/ProjectName/Images.xcassets

Any idea to help me out?

Thanks.

Upvotes: 4

Views: 2038

Answers (1)

Crash
Crash

Reputation: 172

In order to use xcassets catalog, you don't have to use require.

Something like that should work:

<Image source={{uri: 'house'}} style={{width: 40, height: 40}} />

Upvotes: 4

Related Questions