React Native Pick Image From Camera and Gallery Android iOS Tutorial

Selecting image from mobile phone gallery and capture image from camera is very typical for beginners in react native. But now we would do this type of functionality in our react native application using an external library called as React Native Image Picker library. This library supports all type of react native versions and also comes with both android and iOS full application support. So in this tutorial we would going to create a react native application that pick image from mobile phone gallery and select image from mobile phone camera and after selecting show that image inside Image component.

What we are doing in current project – Must Read  :

  • Selecting Image from both Android and iOS mobile phone gallery.
  • Capturing image from both Android and iOS device camera.
  • Show captured image inside Image component.
  • Show selected image from gallery inside Image component.

Important Note : You must follow all the steps exactly as i did in this tutorial, So don’t skip any step and read the full tutorial. Happy Reading . 

Contents in this project React Native Pick Image From Camera and Gallery Tutorial :

1. Start a fresh React Native project. If you don’t know how then read my this tutorial.

2. After creating project Start Command Prompt in your system using Run As Administrator .


3. Now using command prompt locate your project’s folder .

4. Type
npm install reactnativeimagepicker@latest save  inside your project like i did in below screenshot.

5. After successfully installed the React Native Image Picker library you would see message like below screenshot.

6. After installing the library type
reactnative link  command inside your project’s folder. This command would refresh the complete project folder. This command is very important .

7. Screenshot after running
reactnative link  command.

8. Configure Project for Android Devices :

1. Open build.gradle file present in your folder located in YourProject/android .

 2. Replace classpath ‘com.android.tools.build:gradle:2.2.+’ on previous line.

3. Now open YourProjectName/android/gradle/wrapper/gradle-wrapper.properties file and replace previous distributionUrl line to this
distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip  .Below is the complete source code of gradle-wrapper.properties file.

4. Open AndroidManifest.xml file present inside YourProjectNameandroidappsrcmain and Add CAMERA permission and WRITE_EXTERNAL_STORAGE permission.

5. Complete source code of AndroidManifest.xml file after adding both permissions.

9. Configure Project for iOS device :

1. Open ImagePickerProject.xcodeproj file in Xcode in MAC.

2. Open Info.plist file in Xcode.

3. Click on small plus icon present just above the Information Property List .

4. Select Privacy – Camera Usages Description permission like i did in below screenshot.

6. Again Select Privacy – Photo Library Usages permission .

7. Now front of both permissions double click and Add some text like i did, So you remember why this permisson is added.

Here you go now your application is successfully configured for iOS devices. Now its time to start coding .

10. Start Coding :

1. Import AppRegistry, StyleSheet, Text, View, PixelRatio, TouchableOpacity, Image component.

2. Import ImagePicker library.

3. Create State inside your mail class and inside that state create variable named as ImageSource = null .

The ImageSource variable is used to store the selected image URI path.

4. Create function selectPhotoTapped() . This is a inbuilt function of this library.

5. Now before ending selectPhotoTapped() function create another function inside its scope named as ImagePicker.showImagePicker() . This is also inbuilt function of React Native Image Picker Library.

6. Create a Parent View inside the render’s return block.

7. Now inside the Parent View component create TouchableOpacity and call the selectPhotoTapped() function on its onPress.

8. Now Create a Sub View inside TouchableOpacity now using ? ( Ternary Operator ) Set condition that If ImageSource variable === null then it will show a Text component inside the TouchableOpacity or if There is Image Selected( ImageSource variable is full) then it will show the selected image inside the Image component.

9. Create Custom CSS Style sheet.

container : for Parent View.

ImageContainer :  for Image Component ( In which the Selected or Captured Image will be displayed. ).

10. Complete source code for index.android.js / index.ios.js file.

Screenshots in iOS device :

Screenshots in Android Device :

Pick Image

Important Note : In iOS simulator camera will not be worked, because iOS simulator dose not support camera so you need a real iOS mobile phone device to Test camera.