Skip to content
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
33 changes: 24 additions & 9 deletions Example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ios/DocumentScannerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 20 additions & 2 deletions ios/DocumentScannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,33 @@ - (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"];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably either let the user specify a folder name or use the CFBundleDisplayName without spaces maybe?


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]];

[croppedImageData writeToFile:croppedFilePath atomically:YES];
[initialImageData writeToFile:initialFilePath atomically:YES];

self.onPictureTaken(@{
self.onPictureTaken(@{
@"croppedImage": croppedFilePath,
@"initialImage": initialFilePath,
@"rectangleCoordinates": rectangleCoordinates });
Expand All @@ -81,7 +100,6 @@ - (void) capture {
[self stop];
}
}];

}


Expand Down
41 changes: 23 additions & 18 deletions ios/IPDFCameraViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ios/RNPdfScannerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down