The comprehensive camera module for React Native. Including photographs, videos. Same as https://github.com/react-native-community/react-native-camera but without the barcode & face detection.
import { RNCamera } from 'react-native-camera';
Inside your package.json, use this
"react-native-camera": "git+https://git@github.com/react-native-community/react-native-camera"
instead of "react-native-camera": "^1.0.0".
To use the camera on Android you must ask for camera permission:
<uses-permission android:name="android.permission.CAMERA" />To enable video recording feature you have to add the following code to the AndroidManifest.xml:
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />See this doc
- JDK >= 1.7 (if you run on 1.6 you will get an error on "_cameras = new HashMap<>();")
- With iOS 10 and higher you need to add the "Privacy - Camera Usage Description" key to the Info.plist of your project. This should be found in 'your_project/ios/your_project/Info.plist'. Add the following code:
<key>NSCameraUsageDescription</key>
<string>Your message to user when the camera is accessed for the first time</string>
<!-- Include this only if you are planning to use the camera roll -->
<key>NSPhotoLibraryUsageDescription</key>
<string>Your message to user when the photo library is accessed for the first time</string>
<!-- Include this only if you are planning to use the microphone for video recording -->
<key>NSMicrophoneUsageDescription</key>
<string>Your message to user when the microphone is accessed for the first time</string>
-
On Android, you require
buildToolsVersionof25.0.2+. This should easily and automatically be downloaded by Android Studio's SDK Manager. -
On iOS 11 and later you need to add
NSPhotoLibraryAddUsageDescriptionkey to the Info.plist. This key lets you describe the reason your app seeks write-only access to the user’s photo library. Info.plist can be found in 'your_project/ios/your_project/Info.plist'. Add the following code:
<!-- Include this only if you are planning to use the camera roll -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Your message to user when the photo library is accessed for the first time</string>
npm install react-native-camera --savereact-native link react-native-camera
npm install react-native-camera --save- Add the plugin dependency to your Podfile, pointing at the path where NPM installed it:
pod 'react-native-camera', path: '../node_modules/react-native-camera'- Run
pod install
npm install react-native-camera --save- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-cameraand addRNCamera.xcodeproj - Expand the
RNCamera.xcodeproj➜Productsfolder - In XCode, in the project navigator, select your project. Add
libRNCamera.ato your project'sBuild Phases➜Link Binary With Libraries - Click
RNCamera.xcodeprojin the project navigator and go theBuild Settingstab. Make sure 'All' is toggled on (instead of 'Basic'). In theSearch Pathssection, look forHeader Search Pathsand make sure it contains both$(SRCROOT)/../../react-native/Reactand$(SRCROOT)/../../../React- mark both asrecursive.
Take a look into this documentation.
Since 1.0.0, RCTCamera is deprecated, but if you want to use it, you can see its documentation.
We are just beginning a funding campaign for react-native-camera. Contributions are greatly appreciated. When we gain more than $250 we will begin distributing funds to core maintainers in a fully transparent manner. Feedback for this process is welcomed, we will continue to evolve the strategy as we grow and learn more.
Support us with a monthly donation and help us continue our activities. [Become a backer]
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]
Thanks to Brent Vatne (@brentvatne) for the react-native-video module which provided me with a great example of how to set up this module.
