11![ Demo gif] ( https://raw.githubusercontent.com/Michaelvilleneuve/react-native-document-scanner/master/images/demo.gif )
22
3- # React Native Document Scanner (iOS only)
3+ ## Set up dev environment
44
5- ** Check out the android branch if you need both platforms, should be released soon**
5+ [ Medium article] ( https://medium.com/@charpeni/setting-up-an-example-app-for-your-react-native-library-d940c5cf31e4 )
6+
7+ # React Native Document Scanner
68
79Live document detection library. Returns either a URI or a base64 encoded string of the captured image, allowing you to easily store it or use it as you wish !
810
911Features :
10- - Live detection
11- - Perspective correction and crop of the image
12- - Live camera filters (brightness, saturation, contrast)
13- - Flash
14- - Easy to use base64 image
1512
16- #### Can be easily plugged with [ react-native-perspective-image-cropper] ( https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper )
13+ - Live detection
14+ - Perspective correction and crop of the image
15+ - Live camera filters (brightness, saturation, contrast)
16+ - Flash
17+ - Easy to use base64 image
1718
19+ #### Can be easily plugged with [ react-native-perspective-image-cropper] ( https://github.com/Michaelvilleneuve/react-native-perspective-image-cropper )
1820
19- ![ Demo crop gif] ( https://camo.githubusercontent.com/0ac887deaa7263172a5fd2759dba3d692e98585a/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6d69636861656c76696c6c656e657576652f64656d6f2d63726f702e676966 )
21+ ![ Demo crop gif] ( https://camo.githubusercontent.com/0ac887deaa7263172a5fd2759dba3d692e98585a/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6d69636861656c76696c6c656e657576652f64656d6f2d63726f702e676966 )
2022
21- ## Getting started
23+ ## Both Platform
2224
2325Use version >=1.4.1 if you are using react-native 0.48+
2426
@@ -30,21 +32,50 @@ Edit the `info.plist` file in XCode and add the following permission : `NSCamera
3032
3133Remember, this library uses your device camera, you can't run it on a simulator.
3234
33- ### With Cocoapods
35+ ### iOS if you want to use Cocoapods instead of default linking
3436
3537If you want to use Cocoapods insteads of ` react-native link ` , add the following to your Podfile
3638
3739```
3840 pod 'RNPdfScanner', :path => '../node_modules/react-native-document-scanner/ios'
3941```
4042
43+ ### Android Only
44+
45+ If you do not have it already in your project, you must link openCV in your ` settings.gradle ` file
46+
47+ ``` java
48+ include ' :openCVLibrary310'
49+ project(' :openCVLibrary310' ). projectDir = new File (rootProject. projectDir,' ../node_modules/react-native-document-scanner/android/openCVLibrary310' )
50+ ```
51+
52+ #### In android/app/src/main/AndroidManifest.xml
53+
54+ Change manifest header to avoid "Manifest merger error". After you add ` xmlns:tools="http://schemas.android.com/tools" ` should look like this:
55+
56+ ```
57+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.<yourAppName>" xmlns:tools="http://schemas.android.com/tools">
58+ ```
59+
60+ Add ` tools:replace="android:allowBackup" ` in <application tag. It should look like this:
61+
62+ ```
63+ <application tools:replace="android:allowBackup" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme">
64+ ```
65+
66+ Add Camera permissions request:
67+
68+ ```
69+ <uses-permission android:name="android.permission.CAMERA" />
70+ ```
4171
4272## Usage
73+
4374``` javascript
44- import React ,{ Component } from ' react' ;
45- import { View , Image } from ' react-native' ;
75+ import React , { Component } from " react" ;
76+ import { View , Image } from " react-native" ;
4677
47- import DocumentScanner from ' react-native-document-scanner' ;
78+ import DocumentScanner from " react-native-document-scanner" ;
4879
4980class YourComponent extends Component {
5081 render () {
@@ -53,61 +84,71 @@ class YourComponent extends Component {
5384 < DocumentScanner
5485 useBase64
5586 saveInAppDocument= {false }
56- onPictureTaken= {data => this .setState ({
57- image: data .croppedImage ,
58- initialImage: data .initialImage ,
59- rectangleCoordinates: data .rectangleCoordinates ,
60- })}
87+ onPictureTaken= {data =>
88+ this .setState ({
89+ image: data .croppedImage ,
90+ initialImage: data .initialImage ,
91+ rectangleCoordinates: data .rectangleCoordinates
92+ })
93+ }
6194 overlayColor= " rgba(255,130,0, 0.7)"
6295 enableTorch= {false }
6396 brightness= {0.3 }
6497 saturation= {1 }
6598 contrast= {1.1 }
6699 quality= {0.5 }
67- onRectangleDetect= {({ stableCounter, lastDetectionType }) => this .setState ({ stableCounter, lastDetectionType })}
100+ onRectangleDetect= {({ stableCounter, lastDetectionType }) =>
101+ this .setState ({ stableCounter, lastDetectionType })
102+ }
68103 detectionCountBeforeCapture= {5 }
69104 detectionRefreshRateInMS= {50 }
70105 / >
71- < Image source= {{ uri: ` data:image/jpeg;base64,${ this .state .image } ` }} resizeMode= " contain" / >
106+ < Image
107+ source= {{ uri: ` data:image/jpeg;base64,${ this .state .image } ` }}
108+ resizeMode= " contain"
109+ / >
72110 < / View>
73111 );
74112 }
75113}
76-
77114```
78115
79116## Properties
80117
81- | Prop | Default | Type | Description |
82- | :-------- | :----:| :--------:| :----------|
83- | overlayColor | ` none ` | ` string ` | Color of the detected rectangle : rgba recommended |
84- | detectionCountBeforeCapture | ` 5 ` | ` integer ` | Number of correct rectangle to detect before capture |
85- | detectionRefreshRateInMS | ` 50 ` | ` integer ` | Time between two rectangle detection attempt |
86- | enableTorch | ` false ` | ` bool ` | Allows to active or deactivate flash during document detection |
87- | useFrontCam | ` false ` | ` bool ` | Allows you to switch between front and back camera |
88- | brightness | ` 0 ` | ` float ` | Increase or decrease camera brightness. Normal as default. |
89- | saturation | ` 1 ` | ` float ` | Increase or decrease camera saturation. Set ` 0 ` for black & white |
90- | contrast | ` 1 ` | ` float ` | Increase or decrease camera contrast. Normal as default |
91- | quality | ` 0.8 ` | ` float ` | Image compression. Reduces both image size and quality |
92- | useBase64 | ` false ` | ` bool ` | If base64 representation should be passed instead of image uri's |
93- | saveInAppDocument | ` false ` | ` bool ` | If should save in app document in case of not using base 64 |
94- | captureMultiple | ` false ` | ` bool ` | Keeps the scanner on after a successful capture |
118+ | Prop | Platform | Default | Type | Description |
119+ | :-------------------------- | :------: | :-----: | :-------: | :---------------------------------------------------------------- |
120+ | overlayColor | Both | ` none ` | ` string ` | Color of the detected rectangle : rgba recommended |
121+ | detectionCountBeforeCapture | Both | ` 5 ` | ` integer ` | Number of correct rectangle to detect before capture |
122+ | detectionRefreshRateInMS | iOS | ` 50 ` | ` integer ` | Time between two rectangle detection attempt |
123+ | enableTorch | Both | ` false ` | ` bool ` | Allows to active or deactivate flash during document detection |
124+ | useFrontCam | iOS | ` false ` | ` bool ` | Allows you to switch between front and back camera |
125+ | brightness | iOS | ` 0 ` | ` float ` | Increase or decrease camera brightness. Normal as default. |
126+ | saturation | iOS | ` 1 ` | ` float ` | Increase or decrease camera saturation. Set ` 0 ` for black & white |
127+ | contrast | iOS | ` 1 ` | ` float ` | Increase or decrease camera contrast. Normal as default |
128+ | quality | iOS | ` 0.8 ` | ` float ` | Image compression. Reduces both image size and quality |
129+ | useBase64 | iOS | ` false ` | ` bool ` | If base64 representation should be passed instead of image uri's |
130+ | saveInAppDocument | iOS | ` false ` | ` bool ` | If should save in app document in case of not using base 64 |
131+ | captureMultiple | iOS | ` false ` | ` bool ` | Keeps the scanner on after a successful capture |
132+ | saveOnDevice | Android | ` false ` | ` bool ` | Save the image in the device storage (** Need permissions** ) |
95133
96134## Manual capture
97135
98136- First get component ref
137+
99138``` javascript
100- < DocumentScanner ref= {( ref ) => this .scanner = ref} / >
139+ < DocumentScanner ref= {ref => ( this .scanner = ref) } / >
101140```
102141
103142- Then call :
143+
104144``` javascript
105145this .scanner .capture ();
106146```
107147
108- ## Each rectangle detection
148+ ## Each rectangle detection (iOS only)
149+
109150| Props | Params | Type | Description |
110- | ------------------- | ---------------------------------------- | ---------- | ------------- |
151+ | ----------------- | -------------------------------------- | -------- | ----------- |
111152| onRectangleDetect | ` { stableCounter, lastDetectionType } ` | ` object ` | See below |
112153
113154The returned object includes the following keys :
@@ -119,30 +160,22 @@ Number of correctly formated rectangle found (this number triggers capture once
119160- ` lastDetectionType `
120161
121162Enum (0, 1 or 2) corresponding to the type of rectangle found
163+
1221640 . Correctly formated rectangle
1231651 . Wrong perspective, bad angle
124- 2 . Too far
125-
166+ 1 . Too far
126167
127168## Returned image
128169
129- | Prop | Params | Type | Description |
130- | :----------- | :-------: | :--------: | : ----------|
131- | onPictureTaken | ` data ` | ` object ` | Returns the captured image in an object ` { croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' } ` |
170+ | Prop | Params | Type | Description |
171+ | :------------- | :----: | : ------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
172+ | onPictureTaken | ` data ` | ` object ` | Returns the captured image in an object ` { croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' } ` |
132173
133174## Save in app document
134175
135- ![ Demo save document] ( images/demoSaveDocument.png )
136-
137176If you want to use saveInAppDocument options, then don't forget to add those raws in .plist :
177+
138178``` xml
139179<key >LSSupportsOpeningDocumentsInPlace</key >
140180<true />
141181```
142-
143- ### If you prefer manual installation
144-
145- 1 . In XCode, in the project navigator, right click ` Libraries ` ➜ ` Add Files to [your project's name] `
146- 2 . Go to ` node_modules ` ➜ ` react-native-pdf-scanner ` and add ` RNPdfScanner.xcodeproj `
147- 3 . In XCode, in the project navigator, select your project. Add ` libRNPdfScanner.a ` to your project's ` Build Phases ` ➜ ` Link Binary With Libraries `
148- 4 . Run your project (` Cmd+R ` )<
0 commit comments