Skip to content

Commit

Permalink
Merge pull request #78 from vijaysingh-axway/MOD-2445
Browse files Browse the repository at this point in the history
[MOD-2445] : iOS  Camera overlay view randomly disappear
  • Loading branch information
hansemannn authored Aug 13, 2018
2 parents c087ade + b15b0d9 commit 8b9cb18
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 60 deletions.
2 changes: 2 additions & 0 deletions ios/Classes/TiBarcodeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#import "TiBarcodeViewController.h"
#import "TiModule.h"
@class TiOverlayView;
@class TiViewProxy;

@interface TiBarcodeModule : TiModule <TiOverlayViewDelegate> {
@private
TiBarcodeViewController *_barcodeViewController;
MTBCamera _selectedCamera;
MTBTorchMode _selectedLEDMode;
NSString *_displayedMessage;
TiViewProxy *_overlayViewProxy;
}

- (NSNumber *)canShow:(id)unused;
Expand Down
109 changes: 55 additions & 54 deletions ios/Classes/TiBarcodeModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (void)capture:(id)args
NSString *displayedMessage = [TiUtils stringValue:[self valueForUndefinedKey:@"displayedMessage"]];

NSMutableArray *acceptedFormats = [self metaDataObjectListFromFormtArray:[args objectForKey:@"acceptedFormats"]];
TiViewProxy *overlayProxy = [args objectForKey:@"overlay"];
_overlayViewProxy = [args objectForKey:@"overlay"];

if (acceptedFormats.count != 0) {
if ([acceptedFormats containsObject:@"-1"]) {
Expand All @@ -77,8 +77,9 @@ - (void)capture:(id)args
NSError *error = nil;
NSError *cameraError = nil;
UIView *overlayView = nil;
if (overlayProxy != nil) {
overlayView = [self prepareOverlayWithProxy:overlayProxy];
if (_overlayViewProxy != nil) {
[self rememberProxy:_overlayViewProxy];
overlayView = [self prepareOverlayWithProxy:_overlayViewProxy];
}
_barcodeViewController = [[TiBarcodeViewController alloc] initWithObjectTypes:acceptedFormats delegate:self showCancel:showCancel showRectangle:showRectangle withOverlay:overlayView];
[[_barcodeViewController scanner] setCamera:_selectedCamera ?: MTBCameraBack error:&cameraError];
Expand All @@ -104,7 +105,8 @@ - (void)capture:(id)args
if (!keepOpen) {
[self closeScanner];
}
} error:&error];
}
error:&error];

if (error) {
[self fireEvent:@"error"
Expand Down Expand Up @@ -234,62 +236,61 @@ - (NSNumber *)parse:(id)args

#pragma mark Internal


- (NSMutableArray *)metaDataObjectListFromFormtArray:(NSArray *)formatArray
{
// For backward compatibility and parity
NSMutableArray *convertedArray = [NSMutableArray arrayWithCapacity:[formatArray count]];
for (NSNumber *number in formatArray) {
NSString *object = @"-1";
switch ([number integerValue]) {
case TiMetadataObjectTypeNone:
object = @"-1";
break;
case TiMetadataObjectTypeQRCode:
object = AVMetadataObjectTypeQRCode;
break;
case TiMetadataObjectTypeDataMatrixCode:
object = AVMetadataObjectTypeDataMatrixCode;
break;
case TiMetadataObjectTypeUPCECode:
object = AVMetadataObjectTypeUPCECode;
break;
case TiMetadataObjectTypeUPCACode:
object = AVMetadataObjectTypeEAN13Code;
break;
case TiMetadataObjectTypeEAN8Code:
object = AVMetadataObjectTypeEAN8Code;
break;
case TiMetadataObjectTypeEAN13Code:
object = AVMetadataObjectTypeEAN13Code;
break;
case TiMetadataObjectTypeCode128Code:
object = AVMetadataObjectTypeCode128Code;
break;
case TiMetadataObjectTypeCode39Code:
object = AVMetadataObjectTypeCode39Code;
break;
case TiMetadataObjectTypeCode93Code:
object = AVMetadataObjectTypeCode93Code;
break;
case TiMetadataObjectTypeCode39Mod43Code:
object = AVMetadataObjectTypeCode39Mod43Code;
break;
case TiMetadataObjectTypeITF14Code:
object = AVMetadataObjectTypeITF14Code;
break;
case TiMetadataObjectTypePDF417Code:
object = AVMetadataObjectTypePDF417Code;
break;
case TiMetadataObjectTypeAztecCode:
object = AVMetadataObjectTypeAztecCode;
break;
case TiMetadataObjectTypeFace:
object = AVMetadataObjectTypeFace;
break;
case TiMetadataObjectTypeInterleaved2of5Code:
object = AVMetadataObjectTypeInterleaved2of5Code;
break;
case TiMetadataObjectTypeNone:
object = @"-1";
break;
case TiMetadataObjectTypeQRCode:
object = AVMetadataObjectTypeQRCode;
break;
case TiMetadataObjectTypeDataMatrixCode:
object = AVMetadataObjectTypeDataMatrixCode;
break;
case TiMetadataObjectTypeUPCECode:
object = AVMetadataObjectTypeUPCECode;
break;
case TiMetadataObjectTypeUPCACode:
object = AVMetadataObjectTypeEAN13Code;
break;
case TiMetadataObjectTypeEAN8Code:
object = AVMetadataObjectTypeEAN8Code;
break;
case TiMetadataObjectTypeEAN13Code:
object = AVMetadataObjectTypeEAN13Code;
break;
case TiMetadataObjectTypeCode128Code:
object = AVMetadataObjectTypeCode128Code;
break;
case TiMetadataObjectTypeCode39Code:
object = AVMetadataObjectTypeCode39Code;
break;
case TiMetadataObjectTypeCode93Code:
object = AVMetadataObjectTypeCode93Code;
break;
case TiMetadataObjectTypeCode39Mod43Code:
object = AVMetadataObjectTypeCode39Mod43Code;
break;
case TiMetadataObjectTypeITF14Code:
object = AVMetadataObjectTypeITF14Code;
break;
case TiMetadataObjectTypePDF417Code:
object = AVMetadataObjectTypePDF417Code;
break;
case TiMetadataObjectTypeAztecCode:
object = AVMetadataObjectTypeAztecCode;
break;
case TiMetadataObjectTypeFace:
object = AVMetadataObjectTypeFace;
break;
case TiMetadataObjectTypeInterleaved2of5Code:
object = AVMetadataObjectTypeInterleaved2of5Code;
break;
}
[convertedArray addObject:object];
}
Expand Down Expand Up @@ -335,6 +336,7 @@ - (void)closeScanner
[[_barcodeViewController scanner] stopScanning];
}

[self forgetProxy:_overlayViewProxy];
[_barcodeViewController setScanner:nil];
[[[[_barcodeViewController view] subviews] objectAtIndex:0] removeFromSuperview];
[_barcodeViewController dismissViewControllerAnimated:YES completion:nil];
Expand Down Expand Up @@ -619,7 +621,6 @@ - (void)cancelled
MAKE_SYSTEM_PROP(BOOKMARK, 9);
MAKE_SYSTEM_PROP(WIFI, 10);


typedef NS_ENUM(NSInteger, TiMetaDataObjectType) {
TiMetadataObjectTypeNone = -1,
TiMetadataObjectTypeQRCode,
Expand Down
8 changes: 4 additions & 4 deletions ios/Classes/TiBarcodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ - (instancetype)initWithObjectTypes:(NSArray *)objectTypes
return self;
}

- (void)viewDidAppear:(BOOL)animated
- (void)viewWillAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[super viewWillAppear:animated];

[[self view] addSubview:_overlayView];
[[self view] bringSubviewToFront:_overlayView];
}

- (void)viewDidDisappear:(BOOL)animated
- (void)viewWillDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[super viewWillDisappear:animated];

[_overlayView removeFromSuperview];
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/TiOverlayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (id)initWithFrame:(CGRect)frame
[self updateViewsWithFrame:frame];

if (overlay != nil) {
[self addSubview:overlay];
[self.layer addSublayer:overlay.layer];
}
}
return self;
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0.0
version: 2.0.1
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Lets you process 1D/2D barcodes.
Expand Down

0 comments on commit 8b9cb18

Please sign in to comment.