react-native-camera-android
React native camera view for android. Enabling you to take pictures directly on camera view, controlling flash light of the device, and also reading barcode from camera.
A react native camera component inspired by
https://github.com/lwansbrough/react-native-camera
https://github.com/ideacreation/react-native-barcodescanner
Installation
npm i --save react-native-camera-android
Add it to your android project
- In
android/setting.gradle
...include ':ReactNativeCameraAndroid', ':app'project(':ReactNativeCameraAndroid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera-android/android')
- In
android/app/build.gradle
dependencies {
...
...
compile project(':react-native-camera-android')
}
- register module (in MainActivity.java)
// <--- import
Example
var Camera = ; var Example = React;
Usage
All you need is to require
the react-native-camera-android
module and then use the
<Camera/>
tag.
Actions
takePicture
- First add refs tag to your camera:
<Camera ref="cam" />
- Then call the function
this.refs.cam.takePicture()
anywhere you like.
Properties
onPictureTaken
After the picture is taken, the <Camera />
component will return an event to onPictureTaken
, which contains following data payloads.
onPictureTaken = function(event) {}
type
:success
orerror
message
: the result of the callback
onBarCodeRead
Will call the specified method when a barcode is detected in the camera's view.
Event contains data
(barcode value) and type
(barcode type).
The following barcode types can be recognised:
BarcodeFormat.UPC_ABarcodeFormat.UPC_EBarcodeFormat.EAN_13BarcodeFormat.EAN_8BarcodeFormat.RSS_14BarcodeFormat.CODE_39BarcodeFormat.CODE_93BarcodeFormat.CODE_128BarcodeFormat.ITFBarcodeFormat.CODABARBarcodeFormat.QR_CODEBarcodeFormat.DATA_MATRIXBarcodeFormat.PDF_417
torchMode
Values:
on
,
off
(default)
Use the torchMode
property to specify the camera torch mode.
type
Values:
back
(default),
front
Use the type
property to specify the camera to use. If you specify the front camera, but the device has no front camera the back camera is used.
Viewfinder properties
The following properties can be used to style the viewfinder:
viewFinderBackgroundColor
,
viewFinderBorderColor
,
viewFinderBorderWidth
,
viewFinderBorderLength
,
viewFinderDrawLaser
,
viewFinderLaserColor
All color values are strings and must be specified as #AARRGGBB
(alpha, red, green, blue). viewFinderBorderWidth
and viewFinderBorderLength
are numbers, viewFinderDrawLaser
is either true
or false
(default).