Sunday, November 15, 2015

Local Images in React-Native IOS

Looks familiar?
There are several ways to use local images in a react-native app:

  1. Using xcassets folder - source={require('image!bg')}. The images must be in the xcassets folder and according to the docs you should have the image in all the 3 sizes.
  2. Relative path - source={require('./bg.png')}. Note that you have to add the file sufix.
  3. The way it actually works - source={{ uri: "google", isStatic: true }} instead of require('image!google'). This way you can use both images that are in your xcassets folder and those that are not without killing yourself while trying to find the right relative path.

If you got here then you've probably started to use React-Native - don't give up yet- it's awesome!