[barcode] default barCodeTypes to [] if no barcode listener
This commit is contained in:
parent
fae43dd698
commit
9162879305
14
Camera.js
14
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 <RCTCamera ref={CAMERA_REF} {...nativeProps} />;
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -70,6 +70,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule {
|
|||
return Collections.unmodifiableMap(new HashMap<String, Object>() {
|
||||
{
|
||||
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<String, Object> getBarCodeConstants() {
|
||||
return Collections.unmodifiableMap(new HashMap<String, Object>() {
|
||||
{
|
||||
// @TODO add barcode types
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, Object> getTypeConstants() {
|
||||
return Collections.unmodifiableMap(new HashMap<String, Object>() {
|
||||
{
|
||||
|
@ -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
|
||||
|
|
|
@ -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]) {
|
||||
|
|
Loading…
Reference in New Issue