diff --git a/README.md b/README.md index 4869a9f..0f03886 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 | +| timeBetweenCaptures | `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..259a84e --- a/index.js +++ b/index.js @@ -26,6 +26,10 @@ class PdfScanner extends React.Component { NativeModules.RNPdfScannerManager.capture(); } + componentWillUnmount() { + NativeModules.RNPdfScannerManager.stopCamera() + } + render() { return ( ); } @@ -56,6 +61,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..0d9247f --- a/ios/DocumentScannerView.h +++ b/ios/DocumentScannerView.h @@ -11,7 +11,10 @@ @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; +- (void) stopCamera; @end diff --git a/ios/DocumentScannerView.m b/ios/DocumentScannerView.m old mode 100644 new mode 100755 index 2eb5f78..c2c5ee8 --- 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,10 +29,16 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan } if (self.stableCounter > self.detectionCountBeforeCapture){ + if ([self.getLastCapture isEqualToDate:[self.getLastCapture earlierDate:[NSDate date]]] ) { [self capture]; + } } } +- (void) stopCamera { + [self stop]; +} + - (void) capture { [self captureImageWithCompletionHander:^(UIImage *croppedImage, UIImage *initialImage, CIRectangleFeature *rectangleFeature) { if (self.onPictureTaken) { @@ -58,6 +65,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 +81,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 }); @@ -82,10 +90,9 @@ - (void) capture { } if (!self.captureMultiple) { - [self stop]; + [self stopCamera]; } }]; - } diff --git a/ios/RNPdfScannerManager.m b/ios/RNPdfScannerManager.m old mode 100644 new mode 100755 index d197f77..ec637a3 --- a/ios/RNPdfScannerManager.m +++ b/ios/RNPdfScannerManager.m @@ -31,12 +31,17 @@ - (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) { [_scannerView capture]; } +RCT_EXPORT_METHOD(stopCamera) { + [_scannerView stopCamera]; +} + - (UIView*) view { _scannerView = [[DocumentScannerView alloc] init]; return _scannerView;