From 1d48cb0c7138f18eb963cb64f687782dbff1071b Mon Sep 17 00:00:00 2001 From: aboelbisher Date: Sun, 24 Mar 2019 16:00:30 +0200 Subject: [PATCH] Barcode bug fix (#255) * bug fixed * logs and comments * fix --- ios/lib/ReactNativeCameraKit/CKCamera.m | 33 ++++++------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index ce0d302..1eca15d 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -68,7 +68,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ #define CAMERA_OPTION_ON_READ_QR_CODE @"onReadQRCode" #define TIMER_FOCUS_TIME_SECONDS 5 -@interface CKCamera () +@interface CKCamera () @property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer; @@ -121,7 +121,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ - (void)dealloc { [self removeObservers]; - //NSLog(@"dealloc"); +// NSLog(@"dealloc"); } -(PHFetchOptions *)fetchOptions { @@ -140,9 +140,9 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ - (void)removeReactSubview:(UIView *)subview { [subview removeFromSuperview]; + [super removeReactSubview:subview]; } - - (void)removeFromSuperview { @@ -156,7 +156,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ } - - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -175,7 +174,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ [self.layer addSublayer:self.previewLayer]; self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; #endif - UIView *focusView = [[UIView alloc] initWithFrame:CGRectZero]; focusView.backgroundColor = [UIColor clearColor]; focusView.layer.borderColor = [UIColor yellowColor].CGColor; @@ -194,7 +192,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ return self; } - -(void)setCameraOptions:(NSDictionary *)cameraOptions { _cameraOptions = cameraOptions; @@ -246,7 +243,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ // } } - -(void)setupCaptionSession { // Setup the capture session. // In general it is not safe to mutate an AVCaptureSession or any of its inputs, outputs, or connections from multiple threads at the same time. @@ -298,17 +294,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ self.setupResult = CKSetupResultSessionConfigurationFailed; } - [self.session commitConfiguration]; - - [self setOnReadCode:self.onReadCode]; - } ); -} - --(void)setOnReadCode:(RCTDirectEventBlock)onReadCode -{ - if (onReadCode) { - _onReadCode = onReadCode; - AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init]; if ([self.session canAddOutput:output]) { self.metadataOutput = output; @@ -316,7 +301,10 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ [self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; [self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]]; } - } + + [self.session commitConfiguration]; + + } ); } -(void)handleCameraPermission { @@ -817,9 +805,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ +(CGSize)cropImageToPreviewSize:(UIImage*)image size:(CGSize)previewSize { - CGRect ans = CGRectZero; - CGSize centerSize = CGSizeZero; - float imageToPreviewWidthScale = image.size.width/previewSize.width; float imageToPreviewHeightScale = image.size.width/previewSize.width; @@ -1092,8 +1077,8 @@ didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects for(AVMetadataObject *metadataObject in metadataObjects) { if ([metadataObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]] && [self isSupportedBarCodeType:metadataObject.type]) { - AVMetadataMachineReadableCodeObject *code = (AVMetadataMachineReadableCodeObject*)[self.previewLayer transformedMetadataObjectForMetadataObject:metadataObject]; + AVMetadataMachineReadableCodeObject *code = (AVMetadataMachineReadableCodeObject*)[self.previewLayer transformedMetadataObjectForMetadataObject:metadataObject]; if (self.onReadCode && code.stringValue && ![code.stringValue isEqualToString:self.codeStringValue]) { self.onReadCode(@{@"codeStringValue": code.stringValue}); [self stopAnimatingScanner]; @@ -1124,7 +1109,5 @@ const NSString *colorForFrame = @"colorForFrame"; const NSString *isNeedMultipleScanBarcode = @"isNeedMultipleScanBarcode"; - - @end