React Native Camera

React Native Camera Kit

We all usually need a camera in our app and Wix has provided a very good library named react-native-camera-kit. Which is very easy to integrate into your app.

In this example, we will make a home screen to open Camera and in the camera, we will have a capture button, a front to back camera switch button, a flash setting button, and a cancel button to close the camera. So let’s get started.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run

npm install -g react-native-cli

Run the following commands to create a new React Native project

react-native init ProjectName

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next

This will make a project structure with an index file named App.js in your project directory.

Installation of Dependency

To use <CameraKitCameraScreen /> we need to install react-native-camera-kit package. To install this

Open the terminal and jump into your project

cd ProjectName

Run the following command

npm install react-native-camera-kit --save

This command will copy all the dependencies into your node_module directory, You can find the directory in node_module the directory named react-native-camera-kit.

–save is optional, it is just to update the react-native-camera-kit dependency in your package.json file.

Installation of Pod

React Native 0.60 brings the auto-linking feature which links the library automatically and you just need to install the pod file using the following command

cd ios && pod install && cd ..

Permission to use the Camera for Android

We are using a Native API Camera so we need to add some permission into the AndroidManifest.xml file.

Please add the following permissions in your AndroidMnifest.xml. Go to CameraExample -> android -> app -> main -> AndroidMnifest.xml.

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
CAMERATo access the camera
WRITE_EXTERNAL_STORAGETo store the content in the SD card
READ_EXTERNAL_STORAGETo view the content of the SD card

For more about the permission, you can see this post.

Permission to use the Camera for IOS

Please follow the below steps to add the permission in iOS project to use the camera.

Open the project CameraExample -> ios -> ScannerExample.xcworkspace in Xcode.

1. After opening the project in Xcode click on the project from the left sidebar and you will see multiple options in the workspace.

2. Select info tab which is info.plist

3. Click on the plus button to add a permission key “Privacy-Camera Usage Description” and a value which will be visible when permission dialog pops up.

Code to Run Camera in React Native Application

Open App.js in any code editor and replace the code with the following code


//This is an example code for the camera//
import React from 'react';
//import react in our code.
import {
} from 'react-native';
//import all the basic components we are going to use.
import { CameraKitCameraScreen } from 'react-native-camera-kit';
//import CameraKitCameraScreen we are going to use.

export default class App extends React.Component {
  state = { isPermitted: false };
  constructor(props) {
  onPress() {
    var that = this;
    if (Platform.OS === 'android') {
      async function requestCameraPermission() {
        try {
          const granted = await PermissionsAndroid.request(
              title: 'CameraExample App Camera Permission',
              message: 'CameraExample App needs access to your camera ',
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            //If CAMERA Permission is granted
            //Calling the WRITE_EXTERNAL_STORAGE permission function
          } else {
            alert('CAMERA permission denied');
        } catch (err) {
          alert('Camera permission err', err);
      async function requestExternalWritePermission() {
        try {
          const granted = await PermissionsAndroid.request(
              title: 'CameraExample App External Storage Write Permission',
                'CameraExample App needs access to Storage data in your SD Card ',
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            //If WRITE_EXTERNAL_STORAGE Permission is granted
            //Calling the READ_EXTERNAL_STORAGE permission function
          } else {
            alert('WRITE_EXTERNAL_STORAGE permission denied');
        } catch (err) {
          alert('Write permission err', err);
      async function requestExternalReadPermission() {
        try {
          const granted = await PermissionsAndroid.request(
              title: 'CameraExample App Read Storage Read Permission',
              message: 'CameraExample App needs access to your SD Card ',
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            //If READ_EXTERNAL_STORAGE Permission is granted
            //changing the state to re-render and open the camera
            //in place of activity indicator
            that.setState({ isPermitted: true });
          } else {
            alert('READ_EXTERNAL_STORAGE permission denied');
        } catch (err) {
          alert('Read permission err', err);
      //Calling the camera permission function
    } else {
      this.setState({ isPermitted: true });
  onBottomButtonPressed(event) {
    const captureImages = JSON.stringify(event.captureImages);
    if (event.type === 'left') {
      this.setState({ isPermitted: false });
    } else {
        [{ text: 'OK', onPress: () => console.log('OK Pressed') }],
        { cancelable: false }
  render() {
    if (this.state.isPermitted) {
      return (
          // Buttons to perform action done and cancel
          actions={{ rightButtonText: 'Done', leftButtonText: 'Cancel' }}
          onBottomButtonPressed={event => this.onBottomButtonPressed(event)}
            // Flash button images
            on: require('./assets/flashon.png'),
            off: require('./assets/flashoff.png'),
            auto: require('./assets/flashauto.png'),
    } else {
      return (
        <View style={styles.container}>
            <Text>Open Camera</Text>
const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'white',
  button: {
    alignItems: 'center',
    backgroundColor: '#DDDDDD',
    padding: 10,
    width: 300,
    marginTop: 16,

Before running the app you need to make a directory called “assets ” to keep the images that we have used. Download and put all the images in assets as shown


To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

Output Screenshots






That was the React Native Camera. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Related Posts

18 thoughts on “React Native Camera”

  1. The code works fine on android but does not work properly on IOS. It seems the permission functions are only for android so the code keeps getting stuck in the try catch. Any ideas?

    • Hello,
      I have tried it on IOS also but let me confirm if there is any update in it..
      We will confirm you soon.
      Mean while if you found the problem and solution for that please comment to help others..

  2. in this package. in the galleryScreen. if i tap on image the image url is only appended to the state.
    how can i append the full image object with all the attributes i.e filename, size, url etc

    onTapImage(event) {
    const uri = event.nativeEvent.selected;

    if (this.state.images[uri]) {
    delete this.state.images[uri];
    } else {
    this.state.images[uri] = true;
    this.setState({ images: {…this.state.images }})

  3. Hi! I am trying to do as you but there is one problem. nvariant Violation: Invariant Violation: requireNativeComponent: “CameraView” was not found in the UIManager. I do not know what does it mean(((
    I use expo. Is it possible use this library with expo?
    Thank you!

  4. i’ve been tried your tutorial about RN Camera, which the icon can small size, i don’t know the size u wear in assets folder.
    and i want to ask you, how can i set the size in this code ?
    im surely want to know how set the size.
    thankyou before 🙂

    • Sorry but there is no way to set the size of the icon. You have to manually reduce the size of the icon. I have tried it on the request of 1 AboutReact family member like you but it wasn’t worked.
      I have used 32px*32px icon in the example.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.