Skip to content

Commit

Permalink
Merge pull request #92 from jwogan5/master
Browse files Browse the repository at this point in the history
[MOD-2465] : Added ability to prevent rotation of scanner
  • Loading branch information
vijaysingh-axway authored Nov 5, 2018
2 parents 1717bc6 + 26c71c5 commit 13f75ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ios/Classes/TiBarcodeModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (void)capture:(id)args
BOOL animate = [TiUtils boolValue:[args objectForKey:@"animate"] def:YES];
BOOL showCancel = [TiUtils boolValue:@"showCancel" properties:args def:YES];
BOOL showRectangle = [TiUtils boolValue:@"showRectangle" properties:args def:YES];
BOOL preventRotation = [TiUtils boolValue:@"preventRotation" properties:args def: NO];

NSMutableArray *acceptedFormats = [self metaDataObjectListFromFormtArray:[args objectForKey:@"acceptedFormats"]];
_overlayViewProxy = [args objectForKey:@"overlay"];
Expand All @@ -80,7 +81,7 @@ - (void)capture:(id)args
[self rememberProxy:_overlayViewProxy];
overlayView = [self prepareOverlayWithProxy:_overlayViewProxy];
}
_barcodeViewController = [[TiBarcodeViewController alloc] initWithObjectTypes:acceptedFormats delegate:self showCancel:showCancel showRectangle:showRectangle withOverlay:overlayView];
_barcodeViewController = [[TiBarcodeViewController alloc] initWithObjectTypes:acceptedFormats delegate:self showCancel:showCancel showRectangle:showRectangle withOverlay:overlayView preventRotation:preventRotation];
[[_barcodeViewController scanner] setCamera:_selectedCamera ?: MTBCameraBack error:&cameraError];

if (_displayedMessage != nil) {
Expand Down
4 changes: 3 additions & 1 deletion ios/Classes/TiBarcodeViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@private
TiOverlayView *_overlayView;
BOOL _showRectangle;
BOOL _preventRotation;
}

- (TiOverlayView *)overlayView;
Expand All @@ -26,7 +27,8 @@
delegate:(id<TiOverlayViewDelegate>)delegate
showCancel:(BOOL)shouldShowCancel
showRectangle:(BOOL)shouldShowRectangle
withOverlay:(UIView *)overlay;
withOverlay:(UIView *)overlay
preventRotation:(BOOL)preventRotation;

@property (nonatomic, strong) MTBBarcodeScanner *scanner;

Expand Down
13 changes: 13 additions & 0 deletions ios/Classes/TiBarcodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (instancetype)initWithObjectTypes:(NSArray *)objectTypes
showCancel:(BOOL)shouldShowCancel
showRectangle:(BOOL)shouldShowRectangle
withOverlay:(UIView *)overlay
preventRotation:(BOOL)preventRotation
{
self = [super init];
if (self) {
Expand All @@ -34,6 +35,7 @@ - (instancetype)initWithObjectTypes:(NSArray *)objectTypes
withOverlay:overlay];
_showRectangle = shouldShowRectangle;
_overlayView.delegate = delegate;
_preventRotation = preventRotation;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDeviceRotation:)
Expand Down Expand Up @@ -84,6 +86,17 @@ - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
return [[[[TiApp app] controller] topContainerController] preferredInterfaceOrientationForPresentation];
}

- (BOOL)shouldAutorotate
{
[super shouldAutorotate];

if (_preventRotation) {
return NO;
}

return YES;
}

- (void)handleDeviceRotation:(NSNotification *)notification
{
if (_showRectangle) {
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.3
version: 2.0.4
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Lets you process 1D/2D barcodes.
Expand Down

0 comments on commit 13f75ee

Please sign in to comment.