diff --git a/Example/package-lock.json b/Example/package-lock.json index 364cccc..89d83ff 100644 --- a/Example/package-lock.json +++ b/Example/package-lock.json @@ -4385,7 +4385,22 @@ } }, "react-native-document-scanner": { - "version": "file:.." + "version": "file:..", + "requires": { + "react": "16.0.0-beta.5" + }, + "dependencies": { + "react": { + "version": "16.0.0-beta.5", + "bundled": true, + "requires": { + "fbjs": "0.8.16", + "loose-envify": "1.3.1", + "object-assign": "4.1.1", + "prop-types": "15.6.0" + } + } + } }, "react-proxy": { "version": "1.1.8", @@ -5015,14 +5030,6 @@ } } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz", @@ -5042,6 +5049,14 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", diff --git a/ios/DocumentScannerView.h b/ios/DocumentScannerView.h index 50f3d56..9af1308 100644 --- a/ios/DocumentScannerView.h +++ b/ios/DocumentScannerView.h @@ -9,6 +9,7 @@ @property (assign, nonatomic) NSInteger stableCounter; @property (nonatomic, assign) float quality; @property (nonatomic, assign) BOOL useBase64; +@property (nonatomic, assign) BOOL saveOnDisk; @property (nonatomic, assign) BOOL captureMultiple; - (void) capture; diff --git a/ios/DocumentScannerView.m b/ios/DocumentScannerView.m index d3069a1..dfcb891 100644 --- a/ios/DocumentScannerView.m +++ b/ios/DocumentScannerView.m @@ -63,6 +63,25 @@ - (void) capture { @"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], @"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], @"rectangleCoordinates": rectangleCoordinates }); + } else if(self.saveOnDisk){ + NSError *error; + NSFileManager *fileMgr = [NSFileManager defaultManager]; + NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + NSString *dataPath = [documents stringByAppendingPathComponent:@"PJBANK_DOCUMENTS"]; + + if (![fileMgr fileExistsAtPath:dataPath]) + [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder + + NSString *croppedFilePath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; + NSString *initialFilePath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; + + [[NSFileManager defaultManager] createFileAtPath:croppedFilePath contents:croppedImageData attributes:nil]; + [[NSFileManager defaultManager] createFileAtPath:initialFilePath contents:initialImageData attributes:nil]; + + self.onPictureTaken(@{ + @"croppedImage": croppedFilePath, + @"initialImage": initialFilePath, + @"rectangleCoordinates": rectangleCoordinates }); } else { NSString *croppedFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; NSString *initialFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]]; @@ -70,7 +89,7 @@ - (void) capture { [croppedImageData writeToFile:croppedFilePath atomically:YES]; [initialImageData writeToFile:initialFilePath atomically:YES]; - self.onPictureTaken(@{ + self.onPictureTaken(@{ @"croppedImage": croppedFilePath, @"initialImage": initialFilePath, @"rectangleCoordinates": rectangleCoordinates }); @@ -81,7 +100,6 @@ - (void) capture { [self stop]; } }]; - } diff --git a/ios/IPDFCameraViewController.m b/ios/IPDFCameraViewController.m index 20ee126..64281bb 100644 --- a/ios/IPDFCameraViewController.m +++ b/ios/IPDFCameraViewController.m @@ -226,34 +226,39 @@ - (CIImage *)drawHighlightOverlayForPoints:(CIImage *)image topLeft:(CGPoint)top - (void)start { - _isStopped = NO; - - [self.captureSession startRunning]; + if (![self.captureSession isRunning]){ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + _isStopped = NO; + [self.captureSession startRunning]; + + float detectionRefreshRate = _detectionRefreshRateInMS; + CGFloat detectionRefreshRateInSec = detectionRefreshRate/100; + + if (_lastDetectionRate != _detectionRefreshRateInMS) { + if (_borderDetectTimeKeeper) { + [_borderDetectTimeKeeper invalidate]; + } + _borderDetectTimeKeeper = [NSTimer scheduledTimerWithTimeInterval:detectionRefreshRateInSec target:self selector:@selector(enableBorderDetectFrame) userInfo:nil repeats:YES]; + } - float detectionRefreshRate = _detectionRefreshRateInMS; - CGFloat detectionRefreshRateInSec = detectionRefreshRate/100; + [self hideGLKView:NO completion:nil]; - if (_lastDetectionRate != _detectionRefreshRateInMS) { - if (_borderDetectTimeKeeper) { - [_borderDetectTimeKeeper invalidate]; - } - _borderDetectTimeKeeper = [NSTimer scheduledTimerWithTimeInterval:detectionRefreshRateInSec target:self selector:@selector(enableBorderDetectFrame) userInfo:nil repeats:YES]; + _lastDetectionRate = _detectionRefreshRateInMS; + }); } - - [self hideGLKView:NO completion:nil]; - - _lastDetectionRate = _detectionRefreshRateInMS; } - (void)stop { - _isStopped = YES; + if ([self.captureSession isRunning]){ + _isStopped = YES; - [self.captureSession stopRunning]; + [self.captureSession stopRunning]; - [_borderDetectTimeKeeper invalidate]; + [_borderDetectTimeKeeper invalidate]; - [self hideGLKView:YES completion:nil]; + [self hideGLKView:YES completion:nil]; + } } - (void)setEnableTorch:(BOOL)enableTorch diff --git a/ios/RNPdfScannerManager.m b/ios/RNPdfScannerManager.m index 1d30379..8a387e5 100644 --- a/ios/RNPdfScannerManager.m +++ b/ios/RNPdfScannerManager.m @@ -30,6 +30,7 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_VIEW_PROPERTY(quality, float) RCT_EXPORT_VIEW_PROPERTY(brightness, float) RCT_EXPORT_VIEW_PROPERTY(contrast, float) +RCT_EXPORT_VIEW_PROPERTY(saveOnDisk, BOOL) RCT_EXPORT_METHOD(capture) {