2016-11-23 20:59:36 +00:00
# Looking for contributors
Hey there, I'm looking for active contributors to help move the development of this branch forward in a stable and timely fashion. I haven't had a need for this module in quite some time and so my person time is not being allocated to it. If you are interested in contributing more actively, please contact me (same username on Twitter, Facebook, etc.) Thanks!
2016-01-12 23:01:05 +00:00
# react-native-camera [![npm version](https://badge.fury.io/js/react-native-camera.svg)](http://badge.fury.io/js/react-native-camera) [![Gitter](https://badges.gitter.im/lwansbrough/react-native-camera.svg)](https://gitter.im/lwansbrough/react-native-camera)
2015-04-01 01:04:18 +00:00
2016-07-02 19:01:43 +00:00
A camera module for React Native.
2016-02-24 18:59:59 +00:00
2017-01-06 07:44:07 +00:00
#### Breaking Changes
2017-01-06 20:06:02 +00:00
react-native header imports have changed in v0.40, and that means breaking changes for all! [Reference PR & Discussion ](https://github.com/lwansbrough/react-native-camera/pull/544 ).
- if on react-native < 0.40: `npm i react-native-camera@0.4`
2017-02-15 18:28:59 +00:00
- if on react-native >= 0.40 `npm i react-native-camera@0.6`
2017-01-06 07:44:07 +00:00
2017-01-23 03:39:36 +00:00
![5j2jduk ](https://cloud.githubusercontent.com/assets/2302315/22190752/6bc6ccd0-e0da-11e6-8e2f-6f22a3567a57.gif )
2015-04-24 17:52:00 +00:00
2015-04-01 01:02:57 +00:00
## Getting started
2016-09-13 09:08:25 +00:00
### Requirements
1. JDK >= 1.7 (if you run on 1.6 you will get an error on "_cameras = new HashMap< >();")
2016-11-18 22:42:03 +00:00
2. 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 >
2017-01-06 07:22:18 +00:00
< string > Your message to user when the camera is accessed for the first time< / string >
2016-11-29 01:15:42 +00:00
<!-- Include this only if you are planning to use the camera roll -->
2016-11-18 22:42:03 +00:00
< key > NSPhotoLibraryUsageDescription< / key >
2016-11-29 01:15:42 +00:00
< 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 microsphone is accessed for the first time< / string >
2016-11-18 22:42:03 +00:00
```
2016-09-13 09:08:25 +00:00
2016-08-02 01:19:41 +00:00
### Mostly automatic install with react-native
1. `npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save`
3. `react-native link react-native-camera`
2015-04-01 01:02:57 +00:00
2016-07-02 19:01:43 +00:00
### Mostly automatic install with CocoaPods
1. `npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save`
2. 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'
```
3. Run `pod install`
2016-01-25 03:36:29 +00:00
### Manual install
#### iOS
2016-02-04 03:18:00 +00:00
1. `npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save`
2015-04-03 22:59:25 +00:00
2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
2015-04-01 16:37:12 +00:00
3. Go to `node_modules` ➜ `react-native-camera` and add `RCTCamera.xcodeproj`
2015-04-03 22:59:25 +00:00
4. In XCode, in the project navigator, select your project. Add `libRCTCamera.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
2015-11-02 00:46:17 +00:00
5. Click `RCTCamera.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` and `$(SRCROOT)/../../../React` - mark both as `recursive` .
2015-04-01 17:39:51 +00:00
5. Run your project (`Cmd+R`)
2015-04-01 01:02:57 +00:00
2016-01-25 03:36:29 +00:00
#### Android
2016-02-04 03:18:00 +00:00
1. `npm install react-native-camera@https://github.com/lwansbrough/react-native-camera.git --save`
2016-09-13 03:30:02 +00:00
2. Open up `android/app/src/main/java/[...]/MainApplication.java
2016-09-13 08:21:28 +00:00
- Add `import com.lwansbrough.RCTCamera.RCTCameraPackage;` to the imports at the top of the file
2016-09-13 03:30:02 +00:00
- Add `new RCTCameraPackage()` to the list returned by the `getPackages()` method. Add a comma to the previous item if there's already something there.
2016-01-25 03:36:29 +00:00
3. Append the following lines to `android/settings.gradle` :
```
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
```
4. Insert the following lines inside the dependencies block in `android/app/build.gradle` :
```
compile project(':react-native-camera')
```
2017-01-25 19:58:46 +00:00
5. Declare the permissions in your Android Manifest
2016-01-25 03:36:29 +00:00
2017-01-25 19:58:46 +00:00
```
< uses-permission android:name = "android.permission.CAMERA" / >
< uses-feature android:name = "android.hardware.camera" / >
```
2016-01-25 03:36:29 +00:00
2015-04-01 01:02:57 +00:00
## Usage
All you need is to `require` the `react-native-camera` module and then use the
`<Camera/>` tag.
2015-04-01 01:45:47 +00:00
```javascript
2016-02-01 04:47:59 +00:00
'use strict';
2016-06-01 17:30:52 +00:00
import React, { Component } from 'react';
import {
2015-04-01 01:02:57 +00:00
AppRegistry,
2016-02-01 04:47:59 +00:00
Dimensions,
2015-04-01 01:02:57 +00:00
StyleSheet,
Text,
2016-02-01 04:47:59 +00:00
TouchableHighlight,
View
} from 'react-native';
import Camera from 'react-native-camera';
2015-05-01 08:16:32 +00:00
2016-02-01 04:47:59 +00:00
class BadInstagramCloneApp extends Component {
2015-05-01 08:16:32 +00:00
render() {
2015-04-01 01:02:57 +00:00
return (
2016-02-01 04:47:59 +00:00
< View style = {styles.container} >
< Camera
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
2016-03-03 02:03:51 +00:00
aspect={Camera.constants.Aspect.fill}>
2016-02-01 04:47:59 +00:00
< Text style = {styles.capture} onPress = {this.takePicture.bind(this)} > [CAPTURE]< / Text >
< / Camera >
< / View >
2015-04-01 01:02:57 +00:00
);
2016-02-01 04:47:59 +00:00
}
2016-02-24 18:59:59 +00:00
2016-02-01 04:47:59 +00:00
takePicture() {
this.camera.capture()
.then((data) => console.log(data))
.catch(err => console.error(err));
}
}
const styles = StyleSheet.create({
2015-05-05 06:11:10 +00:00
container: {
2016-02-01 04:47:59 +00:00
flex: 1
},
preview: {
2015-05-05 06:11:10 +00:00
flex: 1,
2016-02-01 04:47:59 +00:00
justifyContent: 'flex-end',
2015-05-05 06:11:10 +00:00
alignItems: 'center',
2016-02-01 04:47:59 +00:00
height: Dimensions.get('window').height,
width: Dimensions.get('window').width
2015-05-05 06:11:10 +00:00
},
2016-02-01 04:47:59 +00:00
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
color: '#000',
padding: 10,
margin: 40
}
2015-05-05 06:11:10 +00:00
});
2016-02-01 04:47:59 +00:00
AppRegistry.registerComponent('BadInstagramCloneApp', () => BadInstagramCloneApp);
2015-04-01 01:02:57 +00:00
```
2015-04-04 07:27:56 +00:00
## Properties
2015-04-01 02:38:30 +00:00
#### `aspect`
2015-05-01 08:16:32 +00:00
Values: `Camera.constants.Aspect.fit` or `"fit"` , `Camera.constants.Aspect.fill` or `"fill"` (default), `Camera.constants.Aspect.stretch` or `"stretch"`
The `aspect` property allows you to define how your viewfinder renders the camera's view. For instance, if you have a square viewfinder and you want to fill the it entirely, you have two options: `"fill"` , where the aspect ratio of the camera's view is preserved by cropping the view or `"stretch"` , where the aspect ratio is skewed in order to fit the entire image inside the viewfinder. The other option is `"fit"` , which ensures the camera's entire view fits inside your viewfinder without altering the aspect ratio.
2016-02-01 04:15:00 +00:00
#### `iOS` `captureAudio`
2015-07-10 03:11:50 +00:00
2016-11-18 22:35:26 +00:00
Values: `true` (Boolean), `false` (default)
2015-07-10 03:11:50 +00:00
*Applies to video capture mode only.* Specifies whether or not audio should be captured with the video.
2015-05-01 08:16:32 +00:00
Android support for recording video (#262)
* Initial commit with Android video support
* stopCapture now works
* Bug fixes and parameter enhancements. README updated.
* Modified stopCapture parameter count to match iOS
* fixed promise bug on stopCapture
* Update RCTCameraModule.java
In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches.
* Update RCTCameraModule.java
* Update RCTCamera.java
Creating video functions in style/convention of existing
* Update RCTCameraModule.java
Use new functions for adjusting video capture size and quality
* Update RCTCameraModule.java
Fixes issue where file not video playable (readable) on older devices
* Update AndroidManifest.xml
Since we're reading and writing video and pictures, need permissions for it.
* Fixed upside down camera (on some platforms), and misc bugs and crashes
* Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata
* To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata"
This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092.
* Fixed merge & brought back all improvements from 9ea1ad4
* Fixed logic for video -> camera roll
* Updates
* Uncommenting setProfile
* Fix support for React Native 0.25
* Renamed Camera to index
* * Fix after merge android recording
* * Fixed android camera roll file saving
* Added recording to example
* * Android promise rejections with exceptions
* Fixed preview, video and photo sizes
* Android recording result in new, javascript object, format
* * Removed example.index.android.js as there is Example project
* * Readme for example
* don't force a specific codec
* always use cache dir
* * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent
* * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268:
- fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
2016-08-28 01:49:46 +00:00
#### `captureMode`
2015-05-01 08:16:32 +00:00
2015-07-11 00:02:58 +00:00
Values: `Camera.constants.CaptureMode.still` (default), `Camera.constants.CaptureMode.video`
2015-05-01 08:16:32 +00:00
2015-07-11 00:02:58 +00:00
The type of capture that will be performed by the camera - either a still image or video.
2015-05-01 08:16:32 +00:00
#### `captureTarget`
Minor Android MediaRecorder, sizing, and file improvements (#477)
Android MediaRecorder:
- Most importantly, call Camera.unlock() before setting the camera on the
MediaRecorder instance, and release() not just reset() when releasing the MediaRecorder
instance!
- Add comments and notes for preparing and releasing MediaRecorder instance.
- Add onError callback for errors during recording session.
RCTCameraViewManager, RCTCamera, RCTCameraViewFinder, RCTCameraView:
- Implement setCaptureMode, preparing camera based on captureMode. Currently, the only step that
needs to be taken here is setting the recording hint for videos.
- Handle setting _captureMode instance variable where applicable.
Sizing
- Determine ViewFinder supported sizes based on actual captureMode (i.e., get supported picture
sizes when in still capture mode, and get supported video sizes when in video capture mode).
Output files:
- Get appropriate external storage public directory based on media type (image or video).
- Minor variable renaming to indicate that both images or videos can be saved.
README:
- Update captureTarget to indicate that cameraRoll is the actual default for both systems.
- Small clarification for output data type for deprecated memory captureTarget output.
2016-11-18 06:25:51 +00:00
Values: `Camera.constants.CaptureTarget.cameraRoll` (default), `Camera.constants.CaptureTarget.disk` , `Camera.constants.CaptureTarget.temp` , ~~`Camera.constants.CaptureTarget.memory`~~ (deprecated),
2015-05-01 08:16:32 +00:00
Minor Android MediaRecorder, sizing, and file improvements (#477)
Android MediaRecorder:
- Most importantly, call Camera.unlock() before setting the camera on the
MediaRecorder instance, and release() not just reset() when releasing the MediaRecorder
instance!
- Add comments and notes for preparing and releasing MediaRecorder instance.
- Add onError callback for errors during recording session.
RCTCameraViewManager, RCTCamera, RCTCameraViewFinder, RCTCameraView:
- Implement setCaptureMode, preparing camera based on captureMode. Currently, the only step that
needs to be taken here is setting the recording hint for videos.
- Handle setting _captureMode instance variable where applicable.
Sizing
- Determine ViewFinder supported sizes based on actual captureMode (i.e., get supported picture
sizes when in still capture mode, and get supported video sizes when in video capture mode).
Output files:
- Get appropriate external storage public directory based on media type (image or video).
- Minor variable renaming to indicate that both images or videos can be saved.
README:
- Update captureTarget to indicate that cameraRoll is the actual default for both systems.
- Small clarification for output data type for deprecated memory captureTarget output.
2016-11-18 06:25:51 +00:00
This property allows you to specify the target output of the captured image data. The disk output has been shown to improve capture response time, so that is the recommended value. When using the deprecated memory output, the image binary is sent back as a base64-encoded string.
2015-04-01 02:38:30 +00:00
Android support for recording video (#262)
* Initial commit with Android video support
* stopCapture now works
* Bug fixes and parameter enhancements. README updated.
* Modified stopCapture parameter count to match iOS
* fixed promise bug on stopCapture
* Update RCTCameraModule.java
In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches.
* Update RCTCameraModule.java
* Update RCTCamera.java
Creating video functions in style/convention of existing
* Update RCTCameraModule.java
Use new functions for adjusting video capture size and quality
* Update RCTCameraModule.java
Fixes issue where file not video playable (readable) on older devices
* Update AndroidManifest.xml
Since we're reading and writing video and pictures, need permissions for it.
* Fixed upside down camera (on some platforms), and misc bugs and crashes
* Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata
* To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata"
This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092.
* Fixed merge & brought back all improvements from 9ea1ad4
* Fixed logic for video -> camera roll
* Updates
* Uncommenting setProfile
* Fix support for React Native 0.25
* Renamed Camera to index
* * Fix after merge android recording
* * Fixed android camera roll file saving
* Added recording to example
* * Android promise rejections with exceptions
* Fixed preview, video and photo sizes
* Android recording result in new, javascript object, format
* * Removed example.index.android.js as there is Example project
* * Readme for example
* don't force a specific codec
* always use cache dir
* * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent
* * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268:
- fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
2016-08-28 01:49:46 +00:00
#### `captureQuality`
2016-03-20 19:31:23 +00:00
2016-11-18 22:38:23 +00:00
Values: `Camera.constants.CaptureQuality.high` or `"high"` (default), `Camera.constants.CaptureQuality.medium` or `"medium"` , `Camera.constants.CaptureQuality.low` or `"low"` , `Camera.constants.CaptureQuality.photo` or `"photo"` , `Camera.constants.CaptureQuality["1080p"]` or `"1080p"` , `Camera.constants.CaptureQuality["720p"]` or `"720p"` , `Camera.constants.CaptureQuality["480p"]` or `"480p"` .
2016-03-20 19:31:23 +00:00
This property allows you to specify the quality output of the captured image or video. By default the quality is set to high.
2015-04-01 02:38:30 +00:00
2016-11-18 22:38:23 +00:00
When choosing more-specific quality settings (1080p, 720p, 480p), note that each platform and device supports different valid picture/video sizes, and actual resolution within each of these quality settings might differ. There should not be too much variance (if any) for iOS; 1080p should give 1920x1080, 720p should give 1280x720, and 480p should give 640x480 (note that iOS 480p therefore is NOT the typical 16:9 HD aspect ratio, and the typically-HD camera preview screen may differ greatly in aspect from what you actually record!!). For Android, expect more variance: on most Androids, 1080p *should* give 1920x1080 and 720p *should* give 1280x720; however, 480p will at "best" be 853x480 (16:9 HD aspect ratio), but falls back/down to 800x480, 720x480, or "worse", depending on what is closest-but-less-than 853x480 and available on the actual device. If your application requires knowledge of the precise resolution of the output image/video, you might consider manually determine the actual resolution itself after capture has completed (particularly for 480p on Android).
2016-11-22 00:41:19 +00:00
Android also supports `Camera.constants.CaptureQuality.preview` or `"preview"` which matches the output image to the same one used in the preview
2015-04-08 20:51:31 +00:00
#### `type`
2015-04-02 09:40:03 +00:00
2015-05-01 21:33:23 +00:00
Values: `Camera.constants.Type.front` or `"front"` , `Camera.constants.Type.back` or `"back"` (default)
2015-04-02 09:40:03 +00:00
2015-04-08 20:51:31 +00:00
Use the `type` property to specify which camera to use.
2015-04-02 09:40:03 +00:00
2015-04-01 02:38:30 +00:00
#### `orientation`
2015-05-01 21:33:23 +00:00
Values:
`Camera.constants.Orientation.auto` or `"auto"` (default),
`Camera.constants.Orientation.landscapeLeft` or `"landscapeLeft"` , `Camera.constants.Orientation.landscapeRight` or `"landscapeRight"` , `Camera.constants.Orientation.portrait` or `"portrait"` , `Camera.constants.Orientation.portraitUpsideDown` or `"portraitUpsideDown"`
2015-04-01 02:38:30 +00:00
2015-04-03 22:59:25 +00:00
The `orientation` property allows you to specify the current orientation of the phone to ensure the viewfinder is "the right way up."
2015-04-01 02:38:30 +00:00
2016-04-10 04:56:35 +00:00
#### `Android` `playSoundOnCapture`
Values: `true` (default) or `false`
Android support for recording video (#262)
* Initial commit with Android video support
* stopCapture now works
* Bug fixes and parameter enhancements. README updated.
* Modified stopCapture parameter count to match iOS
* fixed promise bug on stopCapture
* Update RCTCameraModule.java
In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches.
* Update RCTCameraModule.java
* Update RCTCamera.java
Creating video functions in style/convention of existing
* Update RCTCameraModule.java
Use new functions for adjusting video capture size and quality
* Update RCTCameraModule.java
Fixes issue where file not video playable (readable) on older devices
* Update AndroidManifest.xml
Since we're reading and writing video and pictures, need permissions for it.
* Fixed upside down camera (on some platforms), and misc bugs and crashes
* Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata
* To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata"
This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092.
* Fixed merge & brought back all improvements from 9ea1ad4
* Fixed logic for video -> camera roll
* Updates
* Uncommenting setProfile
* Fix support for React Native 0.25
* Renamed Camera to index
* * Fix after merge android recording
* * Fixed android camera roll file saving
* Added recording to example
* * Android promise rejections with exceptions
* Fixed preview, video and photo sizes
* Android recording result in new, javascript object, format
* * Removed example.index.android.js as there is Example project
* * Readme for example
* don't force a specific codec
* always use cache dir
* * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent
* * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268:
- fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
2016-08-28 01:49:46 +00:00
This property allows you to specify whether a shutter sound is played on capture. It is currently android only, pending [a reasonable mute implementation ](http://stackoverflow.com/questions/4401232/avfoundation-how-to-turn-off-the-shutter-sound-when-capturestillimageasynchrono ) in iOS.
2016-04-10 04:56:35 +00:00
2016-12-09 17:18:28 +00:00
#### `onBarCodeRead`
2015-04-19 22:53:30 +00:00
Will call the specified method when a barcode is detected in the camera's view.
Event contains `data` (the data in the barcode) and `bounds` (the rectangle which outlines the barcode.)
2015-04-02 09:40:03 +00:00
2015-07-26 19:32:42 +00:00
The following barcode types can be recognised:
- `aztec`
2017-01-23 07:20:39 +00:00
- `code128`
2015-07-26 19:32:42 +00:00
- `code39`
- `code39mod43`
- `code93`
- `ean13`
- `ean8`
- `pdf417`
- `qr`
- `upce`
2016-02-13 05:59:29 +00:00
- `interleaved2of5` (when available)
- `itf14` (when available)
2015-11-05 19:25:27 +00:00
- `datamatrix` (when available)
2015-07-26 19:32:42 +00:00
The barcode type is provided in the `data` object.
2016-12-09 17:18:28 +00:00
#### `barCodeTypes`
2016-04-10 16:16:21 +00:00
An array of barcode types to search for. Defaults to all types listed above. No effect if `onBarCodeRead` is undefined.
2015-05-30 16:36:55 +00:00
#### `flashMode`
Values:
`Camera.constants.FlashMode.on` ,
`Camera.constants.FlashMode.off` ,
`Camera.constants.FlashMode.auto`
Use the `flashMode` property to specify the camera flash mode.
2015-06-15 18:58:36 +00:00
#### `torchMode`
Values:
`Camera.constants.TorchMode.on` ,
`Camera.constants.TorchMode.off` ,
`Camera.constants.TorchMode.auto`
Use the `torchMode` property to specify the camera torch mode.
2016-02-01 03:46:33 +00:00
#### `onFocusChanged: Event { nativeEvent: { touchPoint: { x, y } }`
2015-08-29 08:24:05 +00:00
2016-02-01 03:46:33 +00:00
Called when a touch focus gesture has been made.
2015-08-29 08:29:10 +00:00
By default, `onFocusChanged` is not defined and tap-to-focus is disabled.
2015-08-29 08:24:05 +00:00
#### `defaultOnFocusComponent`
Values:
`true` (default)
`false`
2015-08-29 08:29:10 +00:00
If `defaultOnFocusComponent` set to false, default internal implementation of visual feedback for tap-to-focus gesture will be disabled.
2016-02-01 03:46:33 +00:00
#### `onZoomChanged: Event { nativeEvent: { velocity, zoomFactor } }`
2015-08-29 08:24:05 +00:00
2016-02-01 03:46:33 +00:00
Called when focus has changed.
2015-08-29 08:29:10 +00:00
By default, `onZoomChanged` is not defined and pinch-to-zoom is disabled.
2015-08-29 08:24:05 +00:00
2016-02-08 12:08:10 +00:00
#### `iOS` `keepAwake`
If set to `true` , the device will not sleep while the camera preview is visible. This mimics the behavior of the default camera app, which keeps the device awake while open.
2016-09-13 16:48:48 +00:00
#### `mirrorImage`
2016-02-24 17:34:43 +00:00
2016-09-13 16:48:48 +00:00
If set to `true` , the image returned will be mirrored.
2016-02-24 17:34:43 +00:00
2016-02-01 03:46:33 +00:00
## Component instance methods
2015-04-02 09:40:03 +00:00
2015-05-01 08:16:32 +00:00
You can access component methods by adding a `ref` (ie. `ref="camera"` ) prop to your `<Camera>` element, then you can use `this.refs.camera.capture(cb)` , etc. inside your component.
2015-04-02 09:40:03 +00:00
2016-01-28 11:14:00 +00:00
#### `capture([options]): Promise`
2015-04-02 09:40:03 +00:00
2016-03-31 19:59:26 +00:00
Captures data from the camera. What is captured is based on the `captureMode` and `captureTarget` props. `captureMode` tells the camera whether you want a still image or video. `captureTarget` allows you to specify how you want the data to be captured and sent back to you. See `captureTarget` under Properties to see the available values.
2015-07-10 03:11:50 +00:00
Supported options:
- `audio` (See `captureAudio` under Properties)
- `mode` (See `captureMode` under Properties)
- `target` (See `captureTarget` under Properties)
2015-08-02 16:09:37 +00:00
- `metadata` This is metadata to be added to the captured image.
- `location` This is the object returned from `navigator.geolocation.getCurrentPosition()` (React Native's geolocation polyfill). It will add GPS metadata to the image.
- `rotation` This will rotate the image by the number of degrees specified.
2015-12-22 21:45:17 +00:00
2016-03-31 19:59:26 +00:00
The promise will be fulfilled with an object with some of the following properties:
- `data` : Returns a base64-encoded string with the capture data (only returned with the deprecated `Camera.constants.CaptureTarget.memory` )
- `path` : Returns the path of the captured image or video file on disk
- `width` : (currently iOS video only) returns the video file's frame width
- `height` : (currently iOS video only) returns the video file's frame height
- `duration` : (currently iOS video only) video file duration
- `size` : (currently iOS video only) video file size (in bytes)
2016-02-01 03:46:33 +00:00
#### `iOS` `getFOV(): Promise`
Returns the camera's current field of view.
2016-03-27 00:27:40 +00:00
#### `hasFlash(): Promise`
2016-02-01 03:46:33 +00:00
Returns whether or not the camera has flash capabilities.
2015-07-11 00:07:44 +00:00
#### `stopCapture()`
Ends the current capture session for video captures. Only applies when the current `captureMode` is `video` .
2015-04-02 09:40:03 +00:00
2016-02-01 03:46:33 +00:00
## Component static methods
Android support for recording video (#262)
* Initial commit with Android video support
* stopCapture now works
* Bug fixes and parameter enhancements. README updated.
* Modified stopCapture parameter count to match iOS
* fixed promise bug on stopCapture
* Update RCTCameraModule.java
In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches.
* Update RCTCameraModule.java
* Update RCTCamera.java
Creating video functions in style/convention of existing
* Update RCTCameraModule.java
Use new functions for adjusting video capture size and quality
* Update RCTCameraModule.java
Fixes issue where file not video playable (readable) on older devices
* Update AndroidManifest.xml
Since we're reading and writing video and pictures, need permissions for it.
* Fixed upside down camera (on some platforms), and misc bugs and crashes
* Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata
* To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata"
This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092.
* Fixed merge & brought back all improvements from 9ea1ad4
* Fixed logic for video -> camera roll
* Updates
* Uncommenting setProfile
* Fix support for React Native 0.25
* Renamed Camera to index
* * Fix after merge android recording
* * Fixed android camera roll file saving
* Added recording to example
* * Android promise rejections with exceptions
* Fixed preview, video and photo sizes
* Android recording result in new, javascript object, format
* * Removed example.index.android.js as there is Example project
* * Readme for example
* don't force a specific codec
* always use cache dir
* * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent
* * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268:
- fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
2016-08-28 01:49:46 +00:00
#### `iOS` `Camera.checkDeviceAuthorizationStatus(): Promise`
2015-12-22 21:45:17 +00:00
2017-02-07 00:38:18 +00:00
Exposes the native API for checking if the device has authorized access to the camera (camera and microphone permissions). Can be used to call before loading the Camera component to ensure proper UX. The promise will be fulfilled with `true` or `false` depending on whether the device is authorized. Note, [as of iOS 10 ](https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/PhotoCaptureGuide/#//apple_ref/doc/uid/TP40017511-CH1-DontLinkElementID_3 ), you will need to add `NSCameraUsageDescription` and `NSMicrophoneUsageDescription` to your XCode project's Info.plist file or you might experience a crash.
2016-12-01 01:25:23 +00:00
#### `iOS` `Camera.checkVideoAuthorizationStatus(): Promise`
2017-02-07 00:38:18 +00:00
The same as `Camera.checkDeviceAuthorizationStatus()` but only checks the camera permission. Note, as of iOS 10, you will need to add `NSCameraUsageDescription` to your XCode project's Info.plist file or you might experience a crash.
2016-12-01 01:25:23 +00:00
#### `iOS` `Camera.checkAudioAuthorizationStatus(): Promise`
2017-02-07 00:38:18 +00:00
The same as `Camera.checkDeviceAuthorizationStatus()` but only checks the microphone permission. Note, as of iOS 10, you will need to add `NSMicrophoneUsageDescription` to your XCode project's Info.plist file or you might experience a crash.
2015-12-22 21:45:17 +00:00
2015-04-04 07:27:56 +00:00
## Subviews
2015-04-03 01:07:22 +00:00
This component supports subviews, so if you wish to use the camera view as a background or if you want to layout buttons/images/etc. inside the camera then you can do that.
2016-05-29 16:55:51 +00:00
## Example
Android support for recording video (#262)
* Initial commit with Android video support
* stopCapture now works
* Bug fixes and parameter enhancements. README updated.
* Modified stopCapture parameter count to match iOS
* fixed promise bug on stopCapture
* Update RCTCameraModule.java
In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches.
* Update RCTCameraModule.java
* Update RCTCamera.java
Creating video functions in style/convention of existing
* Update RCTCameraModule.java
Use new functions for adjusting video capture size and quality
* Update RCTCameraModule.java
Fixes issue where file not video playable (readable) on older devices
* Update AndroidManifest.xml
Since we're reading and writing video and pictures, need permissions for it.
* Fixed upside down camera (on some platforms), and misc bugs and crashes
* Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata
* To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata"
This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092.
* Fixed merge & brought back all improvements from 9ea1ad4
* Fixed logic for video -> camera roll
* Updates
* Uncommenting setProfile
* Fix support for React Native 0.25
* Renamed Camera to index
* * Fix after merge android recording
* * Fixed android camera roll file saving
* Added recording to example
* * Android promise rejections with exceptions
* Fixed preview, video and photo sizes
* Android recording result in new, javascript object, format
* * Removed example.index.android.js as there is Example project
* * Readme for example
* don't force a specific codec
* always use cache dir
* * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent
* * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268:
- fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
2016-08-28 01:49:46 +00:00
To see more of the `react-native-camera` in action, you can check out the source in [Example ](https://github.com/lwansbrough/react-native-camera/tree/master/Example ) folder.
2016-05-29 16:55:51 +00:00
2015-04-01 01:02:57 +00:00
------------
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.