From 812afe8a36a2af90c58e4b7bcbf5dd25b09cd1e3 Mon Sep 17 00:00:00 2001 From: Guilherme Dias Date: Fri, 26 Jan 2018 09:30:33 -0200 Subject: [PATCH 1/3] saveOnDisk --- Example/index.ios.js | 6 +++- Example/ios/Example.xcodeproj/project.pbxproj | 6 ++-- Example/package-lock.json | 33 ++++++++++++++----- ios/DocumentScannerView.h | 1 + ios/DocumentScannerView.m | 22 +++++++++++-- ios/RNPdfScannerManager.m | 1 + 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Example/index.ios.js b/Example/index.ios.js index 6fb2d5f..3dfe3f1 100644 --- a/Example/index.ios.js +++ b/Example/index.ios.js @@ -45,7 +45,10 @@ export default class Example extends Component { : this.setState({ image: data.croppedImage })} + onPictureTaken={data => { + this.setState({ image: data.croppedImage }) + alert(JSON.stringify(data)); + }} overlayColor="rgba(255,130,0, 0.7)" enableTorch={this.state.flashEnabled} useFrontCam={this.state.useFrontCam} @@ -57,6 +60,7 @@ export default class Example extends Component { detectionCountBeforeCapture={10} detectionRefreshRateInMS={50} style={styles.scanner} + //saveOnDisk /> } diff --git a/Example/ios/Example.xcodeproj/project.pbxproj b/Example/ios/Example.xcodeproj/project.pbxproj index 55ebe7c..33c6eeb 100644 --- a/Example/ios/Example.xcodeproj/project.pbxproj +++ b/Example/ios/Example.xcodeproj/project.pbxproj @@ -635,7 +635,7 @@ TestTargetID = 13B07F861A680F5B00A75B9A; }; 13B07F861A680F5B00A75B9A = { - DevelopmentTeam = G2NJHPDYHV; + DevelopmentTeam = S2ZF48QL46; }; 2D02E47A1E0B4A5D006451C7 = { CreatedOnToolsVersion = 8.2.1; @@ -1120,7 +1120,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; - DEVELOPMENT_TEAM = G2NJHPDYHV; + DEVELOPMENT_TEAM = S2ZF48QL46; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-pdf-scanner/ios/**", @@ -1143,7 +1143,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = G2NJHPDYHV; + DEVELOPMENT_TEAM = S2ZF48QL46; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-pdf-scanner/ios/**", 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/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) { From 572d14b7d016251ef7b5e783af0555d9703fd072 Mon Sep 17 00:00:00 2001 From: Guilherme Dias Date: Fri, 26 Jan 2018 10:39:57 -0200 Subject: [PATCH 2/3] remove needless changes --- Example/index.ios.js | 6 +----- Example/ios/Example.xcodeproj/project.pbxproj | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Example/index.ios.js b/Example/index.ios.js index 3dfe3f1..6fb2d5f 100644 --- a/Example/index.ios.js +++ b/Example/index.ios.js @@ -45,10 +45,7 @@ export default class Example extends Component { : { - this.setState({ image: data.croppedImage }) - alert(JSON.stringify(data)); - }} + onPictureTaken={data => this.setState({ image: data.croppedImage })} overlayColor="rgba(255,130,0, 0.7)" enableTorch={this.state.flashEnabled} useFrontCam={this.state.useFrontCam} @@ -60,7 +57,6 @@ export default class Example extends Component { detectionCountBeforeCapture={10} detectionRefreshRateInMS={50} style={styles.scanner} - //saveOnDisk /> } diff --git a/Example/ios/Example.xcodeproj/project.pbxproj b/Example/ios/Example.xcodeproj/project.pbxproj index 33c6eeb..55ebe7c 100644 --- a/Example/ios/Example.xcodeproj/project.pbxproj +++ b/Example/ios/Example.xcodeproj/project.pbxproj @@ -635,7 +635,7 @@ TestTargetID = 13B07F861A680F5B00A75B9A; }; 13B07F861A680F5B00A75B9A = { - DevelopmentTeam = S2ZF48QL46; + DevelopmentTeam = G2NJHPDYHV; }; 2D02E47A1E0B4A5D006451C7 = { CreatedOnToolsVersion = 8.2.1; @@ -1120,7 +1120,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; - DEVELOPMENT_TEAM = S2ZF48QL46; + DEVELOPMENT_TEAM = G2NJHPDYHV; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-pdf-scanner/ios/**", @@ -1143,7 +1143,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = S2ZF48QL46; + DEVELOPMENT_TEAM = G2NJHPDYHV; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/../node_modules/react-native-pdf-scanner/ios/**", From d59094da340a46127b4a1bdf48c6fb1f8843f53f Mon Sep 17 00:00:00 2001 From: Guilherme Dias Date: Mon, 29 Jan 2018 12:12:06 -0200 Subject: [PATCH 3/3] melhoria --- ios/IPDFCameraViewController.m | 41 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) 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