Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer between captures #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class PdfScanner extends React.Component {
NativeModules.RNPdfScannerManager.capture();
}

componentWillUnmount() {
NativeModules.RNPdfScannerManager.stopCamera()
}

render() {
return (
<RNPdfScanner
Expand All @@ -39,6 +43,7 @@ class PdfScanner extends React.Component {
quality={this.getImageQuality()}
detectionCountBeforeCapture={this.props.detectionCountBeforeCapture||5}
detectionRefreshRateInMS={this.props.detectionRefreshRateInMS||50}
timeBetweenCaptures={this.props.timeBetweenCaptures||5}
/>
);
}
Expand All @@ -56,6 +61,7 @@ PdfScanner.propTypes = {
detectionCountBeforeCapture: PropTypes.number,
detectionRefreshRateInMS: PropTypes.number,
quality: PropTypes.number,
timeBetweenCaptures: PropTypes.number,
};

export default PdfScanner;
3 changes: 3 additions & 0 deletions ios/DocumentScannerView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 11 additions & 4 deletions ios/DocumentScannerView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ - (instancetype)init {
if (self) {
[self setEnableBorderDetection:YES];
[self setDelegate: self];
[self setLastCapture:[NSDate date]];
}

return self;
Expand All @@ -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) {
Expand All @@ -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],
Expand All @@ -73,19 +81,18 @@ - (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 });
}
}

if (!self.captureMultiple) {
[self stop];
[self stopCamera];
}
}];

}


Expand Down
5 changes: 5 additions & 0 deletions ios/RNPdfScannerManager.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down