How to get images from camera roll with React Native on Android?


React Native


UPDATE: The CameraRoll Api is available on Android as of React Native 0.19

So you've decided to build a photo gallery component in your React Native app.
On iOS, no problem, you can use the CameraRoll Api.
Unfortunately, you won't have the same luck on Android. Facebook didn't open source the Android version yet...

But do not despair! You can luckily use rn-camera-roll!
This module makes the CameraRoll.getPhotos method available on Android.

You can use the CameraRoll.getPhotos method as you would with the iOS API with the after and the first params:

var CameraRoll = require('rn-camera-roll');

onPhotosFetchedSuccess(data) {  
  var photos = => {
    return asset.node.image;

onPhotosFetchError(error) {  
  // Handle error here

fetchPhotos(count = 10, after) {  
  // Use the CameraRoll API on iOS and Android
    // take the first n photos after given photo uri
    first: count,
    // after
    after: "file:/storage/emulated/0/DCIM/Camera/IMG_20151126_115520477.jpg",
  }, this.onPhotosFetchedSuccess.bind(this), this.onPhotosFetchError.bind(this));

You can now build an awesome photo gallery in your React Native App, even on Android!

Checkout this example of a basic gallery app with infinite scroll:
The result on Android: