maraujop
maraujop

Reputation: 4594

Resource ID #0x0 React Native

I'm trying to set an icon in Android with react-native. My code looks like this:

<ToolbarAndroid
  actions={[]}
  navIcon={require('image!test')}
  onIconClicked={navigationOperations.pop}
  style={styles.toolbar}
  titleColor="white"
  title={route.event.title} />

I've got a non-corrupt test.png file under app/src/main/res/mipmap-hdpi/test.png (after adding the image I've run react-native run-android) and I'm getting a Resource ID #0x0 :

Resource ID #0x0

However, if I change the image name to something bogus, the error

"Requiring unknown module "image!testttt". If you are sure the module is there, try restarting the packager"

I don't know what's going on, I've seen an exact example of this in react-native Movies example, that actually works in my computer.

Upvotes: 3

Views: 3217

Answers (1)

maraujop
maraujop

Reputation: 4594

I found what was happening. When I created my project react-native created mipmap directories: mipmap-hdpi, mipmap-mdpi, etc.

These directories in Android are for icons only. I deleted these directories and created drawable ones and put my icon application inside drawable. I adjusted my AndroidManifest to point to @drawable/icon. After this a rebuild the android application and relaunch the packager. It started working right after that with react-native 0.11.0

Upvotes: 4

Related Questions