From d96be08a1ee0756bebbe3f400740c40a96a6beeb Mon Sep 17 00:00:00 2001 From: Weslley Rocha Date: Mon, 11 Feb 2019 17:42:42 -0200 Subject: [PATCH 1/4] timer --- README.md | 1 + index.js | 2 ++ ios/DocumentScannerView.h | 2 ++ ios/DocumentScannerView.m | 9 ++++++--- ios/RNPdfScannerManager.m | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) mode change 100644 => 100755 index.js mode change 100644 => 100755 ios/DocumentScannerView.h mode change 100644 => 100755 ios/DocumentScannerView.m mode change 100644 => 100755 ios/RNPdfScannerManager.m diff --git a/README.md b/README.md index 4869a9f..78f34d6 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ class YourComponent extends Component { | useBase64 | `false` | `bool` | If base64 representation should be passed instead of image uri's | | saveInAppDocument | `false` | `bool` | If should save in app document in case of not using base 64 | | captureMultiple | `false` | `bool` | Keeps the scanner on after a successful capture | +| timeBetweenCapture | `5` | `integer` | Time in seconds the camera will not capture after a successful capture (this don't affect manual capture) | ## Manual capture diff --git a/index.js b/index.js old mode 100644 new mode 100755 index 1fe634b..06ddd93 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ class PdfScanner extends React.Component { quality={this.getImageQuality()} detectionCountBeforeCapture={this.props.detectionCountBeforeCapture||5} detectionRefreshRateInMS={this.props.detectionRefreshRateInMS||50} + timeBetweenCaptures={this.props.timeBetweenCaptures||5} /> ); } @@ -56,6 +57,7 @@ PdfScanner.propTypes = { detectionCountBeforeCapture: PropTypes.number, detectionRefreshRateInMS: PropTypes.number, quality: PropTypes.number, + timeBetweenCaptures: PropTypes.number, }; export default PdfScanner; diff --git a/ios/DocumentScannerView.h b/ios/DocumentScannerView.h old mode 100644 new mode 100755 index d50e849..f681d2e --- a/ios/DocumentScannerView.h +++ b/ios/DocumentScannerView.h @@ -11,6 +11,8 @@ @property (nonatomic, assign) BOOL useBase64; @property (nonatomic, assign) BOOL captureMultiple; @property (nonatomic, assign) BOOL saveInAppDocument; +@property (copy, nonatomic, getter=getLastCapture, setter=setLastCapture:) NSDate * lastCapture; +@property (nonatomic, assign) NSInteger timeBetweenCaptures; - (void) capture; diff --git a/ios/DocumentScannerView.m b/ios/DocumentScannerView.m old mode 100644 new mode 100755 index 2eb5f78..c648942 --- a/ios/DocumentScannerView.m +++ b/ios/DocumentScannerView.m @@ -8,6 +8,7 @@ - (instancetype)init { if (self) { [self setEnableBorderDetection:YES]; [self setDelegate: self]; + [self setLastCapture:[NSDate date]]; } return self; @@ -28,7 +29,9 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan } if (self.stableCounter > self.detectionCountBeforeCapture){ + if ([self.getLastCapture isEqualToDate:[self.getLastCapture earlierDate:[NSDate date]]] ) { [self capture]; + } } } @@ -58,6 +61,7 @@ - (void) capture { @"bottomRight": @{ @"y": @(rectangleFeature.topRight.x), @"x": @(rectangleFeature.topRight.y)}, } : [NSNull null]; if (self.useBase64) { + [self setLastCapture:[NSDate dateWithTimeIntervalSinceNow:self.timeBetweenCaptures]]; self.onPictureTaken(@{ @"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], @"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], @@ -73,8 +77,8 @@ - (void) capture { [croppedImageData writeToFile:croppedFilePath atomically:YES]; [initialImageData writeToFile:initialFilePath atomically:YES]; - - self.onPictureTaken(@{ + [self setLastCapture:[NSDate dateWithTimeIntervalSinceNow:self.timeBetweenCaptures]]; + self.onPictureTaken(@{ @"croppedImage": croppedFilePath, @"initialImage": initialFilePath, @"rectangleCoordinates": rectangleCoordinates }); @@ -85,7 +89,6 @@ - (void) capture { [self stop]; } }]; - } diff --git a/ios/RNPdfScannerManager.m b/ios/RNPdfScannerManager.m old mode 100644 new mode 100755 index d197f77..034c245 --- a/ios/RNPdfScannerManager.m +++ b/ios/RNPdfScannerManager.m @@ -31,6 +31,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(timeBetweenCaptures, NSInteger) RCT_EXPORT_METHOD(capture) { From 7010331f41efc82757372f7af09a2d64d8ee3cee Mon Sep 17 00:00:00 2001 From: Weslley Rocha Date: Mon, 11 Feb 2019 18:11:48 -0200 Subject: [PATCH 2/4] feature/stop camera --- index.js | 4 ++++ ios/DocumentScannerView.h | 1 + ios/DocumentScannerView.m | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 06ddd93..259a84e 100755 --- a/index.js +++ b/index.js @@ -26,6 +26,10 @@ class PdfScanner extends React.Component { NativeModules.RNPdfScannerManager.capture(); } + componentWillUnmount() { + NativeModules.RNPdfScannerManager.stopCamera() + } + render() { return ( Date: Tue, 12 Feb 2019 10:50:33 -0200 Subject: [PATCH 3/4] Update RNPdfScannerManager.m --- ios/RNPdfScannerManager.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ios/RNPdfScannerManager.m b/ios/RNPdfScannerManager.m index 034c245..ec637a3 100755 --- a/ios/RNPdfScannerManager.m +++ b/ios/RNPdfScannerManager.m @@ -38,6 +38,10 @@ - (dispatch_queue_t)methodQueue [_scannerView capture]; } +RCT_EXPORT_METHOD(stopCamera) { + [_scannerView stopCamera]; +} + - (UIView*) view { _scannerView = [[DocumentScannerView alloc] init]; return _scannerView; From d1a047b71c0a6a459a7a6bda7fd0639d261901d8 Mon Sep 17 00:00:00 2001 From: Weslley Nascimento Rocha Date: Wed, 13 Feb 2019 11:48:23 -0200 Subject: [PATCH 4/4] timeBetweenCapture -> timeBetweenCaptures --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 78f34d6..0f03886 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ class YourComponent extends Component { | useBase64 | `false` | `bool` | If base64 representation should be passed instead of image uri's | | saveInAppDocument | `false` | `bool` | If should save in app document in case of not using base 64 | | captureMultiple | `false` | `bool` | Keeps the scanner on after a successful capture | -| timeBetweenCapture | `5` | `integer` | Time in seconds the camera will not capture after a successful capture (this don't affect manual capture) | +| timeBetweenCaptures | `5` | `integer` | Time in seconds the camera will not capture after a successful capture (this don't affect manual capture) | ## Manual capture