diff --git a/Camera.js b/Camera.js
index 29c4f82..57fd060 100644
--- a/Camera.js
+++ b/Camera.js
@@ -12,7 +12,7 @@ import {
const CameraManager = NativeModules.CameraManager || NativeModules.CameraModule;
const CAMERA_REF = 'camera';
-function convertStringProps(props) {
+function convertNativeProps(props) {
const newProps = { ...props };
if (typeof props.aspect === 'string') {
newProps.aspect = Camera.constants.Aspect[props.aspect];
@@ -42,6 +42,11 @@ function convertStringProps(props) {
newProps.captureMode = Camera.constants.CaptureMode[props.captureMode];
}
+ // do not register barCodeTypes if no barcode listener
+ if (typeof props.onBarCodeRead !== 'function') {
+ newProps.barCodeTypes = [];
+ }
+
return newProps;
}
@@ -117,7 +122,7 @@ export default class Camera extends Component {
playSoundOnCapture: true,
torchMode: CameraManager.TorchMode.off,
mirrorImage: false,
- barCodeTypes: [],
+ barCodeTypes: Object.keys(CameraManager.BarCodeType),
};
static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus;
@@ -159,15 +164,16 @@ export default class Camera extends Component {
render() {
const style = [styles.base, this.props.style];
- const nativeProps = convertStringProps(this.props);
+ const nativeProps = convertNativeProps(this.props);
return ;
}
capture(options) {
- const props = convertStringProps(this.props);
+ const props = convertNativeProps(this.props);
options = {
audio: props.captureAudio,
+ barCodeTypes: props.barCodeTypes,
mode: props.captureMode,
playSoundOnCapture: props.playSoundOnCapture,
target: props.captureTarget,
diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java
index 0dde182..bdd033b 100644
--- a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java
+++ b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java
@@ -70,6 +70,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
return Collections.unmodifiableMap(new HashMap() {
{
put("Aspect", getAspectConstants());
+ put("BarCodeType", getBarCodeConstants());
put("Type", getTypeConstants());
put("CaptureQuality", getCaptureQualityConstants());
put("CaptureMode", getCaptureModeConstants());
@@ -89,6 +90,14 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
});
}
+ private Map getBarCodeConstants() {
+ return Collections.unmodifiableMap(new HashMap() {
+ {
+ // @TODO add barcode types
+ }
+ });
+ }
+
private Map getTypeConstants() {
return Collections.unmodifiableMap(new HashMap() {
{
@@ -174,7 +183,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
}
-
+
RCTCamera.getInstance().setCaptureQuality(options.getInt("type"), options.getString("quality"));
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m
index 624ca36..2c64f1a 100644
--- a/ios/RCTCameraManager.m
+++ b/ios/RCTCameraManager.m
@@ -48,26 +48,26 @@ RCT_EXPORT_VIEW_PROPERTY(barCodeTypes, NSStringArray);
@"fill": @(RCTCameraAspectFill)
},
@"BarCodeType": @{
- @"upce": AVMetadataObjectTypeUPCECode,
- @"code39": AVMetadataObjectTypeCode39Code,
- @"code39mod43": AVMetadataObjectTypeCode39Mod43Code,
- @"ean13": AVMetadataObjectTypeEAN13Code,
- @"ean8": AVMetadataObjectTypeEAN8Code,
- @"code93": AVMetadataObjectTypeCode93Code,
- @"code138": AVMetadataObjectTypeCode128Code,
- @"pdf417": AVMetadataObjectTypePDF417Code,
- @"qr": AVMetadataObjectTypeQRCode,
- @"aztec": AVMetadataObjectTypeAztecCode
- #ifdef AVMetadataObjectTypeInterleaved2of5Code
- ,@"interleaved2of5": AVMetadataObjectTypeInterleaved2of5Code
- # endif
- #ifdef AVMetadataObjectTypeITF14Code
- ,@"itf14": AVMetadataObjectTypeITF14Code
- # endif
- #ifdef AVMetadataObjectTypeDataMatrixCode
- ,@"datamatrix": AVMetadataObjectTypeDataMatrixCode
- # endif
- },
+ @"upce": AVMetadataObjectTypeUPCECode,
+ @"code39": AVMetadataObjectTypeCode39Code,
+ @"code39mod43": AVMetadataObjectTypeCode39Mod43Code,
+ @"ean13": AVMetadataObjectTypeEAN13Code,
+ @"ean8": AVMetadataObjectTypeEAN8Code,
+ @"code93": AVMetadataObjectTypeCode93Code,
+ @"code138": AVMetadataObjectTypeCode128Code,
+ @"pdf417": AVMetadataObjectTypePDF417Code,
+ @"qr": AVMetadataObjectTypeQRCode,
+ @"aztec": AVMetadataObjectTypeAztecCode
+ #ifdef AVMetadataObjectTypeInterleaved2of5Code
+ ,@"interleaved2of5": AVMetadataObjectTypeInterleaved2of5Code
+ # endif
+ #ifdef AVMetadataObjectTypeITF14Code
+ ,@"itf14": AVMetadataObjectTypeITF14Code
+ # endif
+ #ifdef AVMetadataObjectTypeDataMatrixCode
+ ,@"datamatrix": AVMetadataObjectTypeDataMatrixCode
+ # endif
+ },
@"Type": @{
@"front": @(RCTCameraTypeFront),
@"back": @(RCTCameraTypeBack)
@@ -157,7 +157,7 @@ RCT_EXPORT_METHOD(checkDeviceAuthorizationStatus:(RCTPromiseResolveBlock)resolve
RCT_EXPORT_METHOD(checkVideoAuthorizationStatus:(RCTPromiseResolveBlock)resolve
reject:(__unused RCTPromiseRejectBlock)reject) {
__block NSString *mediaType = AVMediaTypeVideo;
-
+
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
resolve(@(granted));
}];
@@ -669,7 +669,7 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
AVAssetTrack* videoTrack = [[videoAsAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
float videoWidth;
float videoHeight;
-
+
CGSize videoSize = [videoTrack naturalSize];
CGAffineTransform txf = [videoTrack preferredTransform];
@@ -682,14 +682,14 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
videoWidth = videoSize.height;
videoHeight = videoSize.width;
}
-
+
NSMutableDictionary *videoInfo = [NSMutableDictionary dictionaryWithDictionary:@{
@"duration":[NSNumber numberWithFloat:CMTimeGetSeconds(videoAsAsset.duration)],
@"width":[NSNumber numberWithFloat:videoWidth],
@"height":[NSNumber numberWithFloat:videoHeight],
@"size":[NSNumber numberWithLongLong:captureOutput.recordedFileSize],
}];
-
+
if (self.videoTarget == RCTCameraCaptureTargetCameraRoll) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL]) {