Barcode bug fix (#255)

* bug fixed

* logs and comments

* fix
This commit is contained in:
aboelbisher 2019-03-24 16:00:30 +02:00 committed by Ran Greenberg
parent 7a12d7841d
commit 1d48cb0c71
1 changed files with 8 additions and 25 deletions

View File

@ -68,7 +68,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
#define CAMERA_OPTION_ON_READ_QR_CODE @"onReadQRCode" #define CAMERA_OPTION_ON_READ_QR_CODE @"onReadQRCode"
#define TIMER_FOCUS_TIME_SECONDS 5 #define TIMER_FOCUS_TIME_SECONDS 5
@interface CKCamera () <AVCaptureFileOutputRecordingDelegate, AVCaptureMetadataOutputObjectsDelegate> @interface CKCamera () <AVCaptureMetadataOutputObjectsDelegate>
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer; @property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@ -121,7 +121,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
- (void)dealloc - (void)dealloc
{ {
[self removeObservers]; [self removeObservers];
//NSLog(@"dealloc"); // NSLog(@"dealloc");
} }
-(PHFetchOptions *)fetchOptions { -(PHFetchOptions *)fetchOptions {
@ -140,9 +140,9 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
- (void)removeReactSubview:(UIView *)subview - (void)removeReactSubview:(UIView *)subview
{ {
[subview removeFromSuperview]; [subview removeFromSuperview];
[super removeReactSubview:subview];
} }
- (void)removeFromSuperview - (void)removeFromSuperview
{ {
@ -156,7 +156,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
} }
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
@ -175,7 +174,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
[self.layer addSublayer:self.previewLayer]; [self.layer addSublayer:self.previewLayer];
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
#endif #endif
UIView *focusView = [[UIView alloc] initWithFrame:CGRectZero]; UIView *focusView = [[UIView alloc] initWithFrame:CGRectZero];
focusView.backgroundColor = [UIColor clearColor]; focusView.backgroundColor = [UIColor clearColor];
focusView.layer.borderColor = [UIColor yellowColor].CGColor; focusView.layer.borderColor = [UIColor yellowColor].CGColor;
@ -194,7 +192,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
return self; return self;
} }
-(void)setCameraOptions:(NSDictionary *)cameraOptions { -(void)setCameraOptions:(NSDictionary *)cameraOptions {
_cameraOptions = cameraOptions; _cameraOptions = cameraOptions;
@ -246,7 +243,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
// } // }
} }
-(void)setupCaptionSession { -(void)setupCaptionSession {
// Setup the capture session. // 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. // 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.setupResult = CKSetupResultSessionConfigurationFailed;
} }
[self.session commitConfiguration];
[self setOnReadCode:self.onReadCode];
} );
}
-(void)setOnReadCode:(RCTDirectEventBlock)onReadCode
{
if (onReadCode) {
_onReadCode = onReadCode;
AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init]; AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init];
if ([self.session canAddOutput:output]) { if ([self.session canAddOutput:output]) {
self.metadataOutput = output; self.metadataOutput = output;
@ -316,7 +301,10 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
[self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; [self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]]; [self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]];
} }
}
[self.session commitConfiguration];
} );
} }
-(void)handleCameraPermission { -(void)handleCameraPermission {
@ -817,9 +805,6 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
+(CGSize)cropImageToPreviewSize:(UIImage*)image size:(CGSize)previewSize { +(CGSize)cropImageToPreviewSize:(UIImage*)image size:(CGSize)previewSize {
CGRect ans = CGRectZero;
CGSize centerSize = CGSizeZero;
float imageToPreviewWidthScale = image.size.width/previewSize.width; float imageToPreviewWidthScale = image.size.width/previewSize.width;
float imageToPreviewHeightScale = 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) for(AVMetadataObject *metadataObject in metadataObjects)
{ {
if ([metadataObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]] && [self isSupportedBarCodeType:metadataObject.type]) { 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]) { if (self.onReadCode && code.stringValue && ![code.stringValue isEqualToString:self.codeStringValue]) {
self.onReadCode(@{@"codeStringValue": code.stringValue}); self.onReadCode(@{@"codeStringValue": code.stringValue});
[self stopAnimatingScanner]; [self stopAnimatingScanner];
@ -1124,7 +1109,5 @@ const NSString *colorForFrame = @"colorForFrame";
const NSString *isNeedMultipleScanBarcode = @"isNeedMultipleScanBarcode"; const NSString *isNeedMultipleScanBarcode = @"isNeedMultipleScanBarcode";
@end @end