Skip to content

Commit 22c2827

Browse files
author
Michaël Villeneuve
authored
Merge pull request #38 from Pompette/master
Feature save in app document
2 parents 6ed55f8 + 10678dd commit 22c2827

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class YourComponent extends Component {
5050
<View>
5151
<DocumentScanner
5252
useBase64
53+
saveInAppDocument={false}
5354
onPictureTaken={data => this.setState({
5455
image: data.croppedImage,
5556
initialImage: data.initialImage,
@@ -87,6 +88,7 @@ class YourComponent extends Component {
8788
| contrast | `1` | `float` | Increase or decrease camera contrast. Normal as default |
8889
| quality | `0.8` | `float` | Image compression. Reduces both image size and quality |
8990
| useBase64 | `false` | `bool` | If base64 representation should be passed instead of image uri's |
91+
| saveInAppDocument | `false` | `bool` | If should save in app document in case of not using base 64 |
9092
| captureMultiple | `false` | `bool` | Keeps the scanner on after a successful capture |
9193

9294
## Manual capture
@@ -126,7 +128,15 @@ Enum (0, 1 or 2) corresponding to the type of rectangle found
126128
| :----------- |:-------:| :--------:| :----------|
127129
| onPictureTaken | `data` | `object` | Returns the captured image in an object `{ croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' }` |
128130

131+
## Save in app document
129132

133+
![Demo save document](images/demoSaveDocument.png)
134+
135+
If you want to use saveInAppDocument options, then don't forget to add those raws in .plist :
136+
```xml
137+
<key>LSSupportsOpeningDocumentsInPlace</key>
138+
<true/>
139+
```
130140

131141
### If you prefer manual installation
132142

images/demoSaveDocument.png

254 KB
Loading

ios/DocumentScannerView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@property (nonatomic, assign) float quality;
1111
@property (nonatomic, assign) BOOL useBase64;
1212
@property (nonatomic, assign) BOOL captureMultiple;
13+
@property (nonatomic, assign) BOOL saveInAppDocument;
1314

1415
- (void) capture;
1516

ios/DocumentScannerView.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ - (void) capture {
5757
@"bottomLeft": @{ @"y": @(rectangleFeature.bottomRight.x), @"x": @(rectangleFeature.bottomRight.y)},
5858
@"bottomRight": @{ @"y": @(rectangleFeature.topRight.x), @"x": @(rectangleFeature.topRight.y)},
5959
} : [NSNull null];
60-
6160
if (self.useBase64) {
6261
self.onPictureTaken(@{
6362
@"croppedImage": [croppedImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
6463
@"initialImage": [initialImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength],
6564
@"rectangleCoordinates": rectangleCoordinates });
66-
} else {
67-
NSString *croppedFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
68-
NSString *initialFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
65+
}
66+
else {
67+
NSString *dir = NSTemporaryDirectory();
68+
if (self.saveInAppDocument) {
69+
dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
70+
}
71+
NSString *croppedFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"cropped_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
72+
NSString *initialFilePath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"initial_img_%i.jpeg",(int)[NSDate date].timeIntervalSince1970]];
6973

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

ios/RNPdfScannerManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ - (dispatch_queue_t)methodQueue
2323
RCT_EXPORT_VIEW_PROPERTY(enableTorch, BOOL)
2424
RCT_EXPORT_VIEW_PROPERTY(useFrontCam, BOOL)
2525
RCT_EXPORT_VIEW_PROPERTY(useBase64, BOOL)
26+
RCT_EXPORT_VIEW_PROPERTY(saveInAppDocument, BOOL)
2627
RCT_EXPORT_VIEW_PROPERTY(captureMultiple, BOOL)
2728
RCT_EXPORT_VIEW_PROPERTY(detectionCountBeforeCapture, NSInteger)
2829
RCT_EXPORT_VIEW_PROPERTY(detectionRefreshRateInMS, NSInteger)

0 commit comments

Comments
 (0)