diff --git a/Example/android/app/build.gradle b/Example/android/app/build.gradle index b6298e9..827aa14 100644 --- a/Example/android/app/build.gradle +++ b/Example/android/app/build.gradle @@ -133,6 +133,7 @@ android { } dependencies { + compile project(':react-native-document-scanner') compile project(':react-native-pdf-scanner') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" diff --git a/Example/android/app/src/main/java/com/example/MainApplication.java b/Example/android/app/src/main/java/com/example/MainApplication.java index cc82cae..c320e29 100644 --- a/Example/android/app/src/main/java/com/example/MainApplication.java +++ b/Example/android/app/src/main/java/com/example/MainApplication.java @@ -4,6 +4,7 @@ import com.facebook.react.ReactApplication; import com.reactlibrary.RNPdfScannerPackage; +import com.reactlibrary.RNPdfScannerPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; @@ -24,6 +25,7 @@ public boolean getUseDeveloperSupport() { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new RNPdfScannerPackage(), new RNPdfScannerPackage() ); } diff --git a/Example/android/settings.gradle b/Example/android/settings.gradle index 82e512a..f792bbc 100644 --- a/Example/android/settings.gradle +++ b/Example/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'Example' +include ':react-native-document-scanner' +project(':react-native-document-scanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-scanner/android') include ':react-native-pdf-scanner' project(':react-native-pdf-scanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pdf-scanner/android') diff --git a/Example/index.ios.js b/Example/index.ios.js index 3d236d1..08725af 100644 --- a/Example/index.ios.js +++ b/Example/index.ios.js @@ -13,7 +13,7 @@ import { TouchableOpacity, View } from 'react-native'; -import PdfScanner from 'react-native-pdf-scanner'; +import Scanner from 'react-native-document-scanner'; export default class Example extends Component { constructor(props) { @@ -24,23 +24,42 @@ export default class Example extends Component { }; } + renderDetectionType() { + switch (this.state.lastDetectionType) { + case 0: + return "Correct rectangle found" + case 1: + return "Bad angle found"; + case 2: + return "Rectangle too far"; + default: + return "No rectangle detected yet"; + } + } + render() { return ( {this.state.image ? : - this.setState({ image: data.image })} overlayColor="rgba(255,130,0, 0.7)" enableTorch={this.state.flashEnabled} - brightness={0} - saturation={1} - contrast={1.1} + brightness={0.2} + saturation={0} + contrast={1.2} + onRectangleDetect={({ stableCounter, lastDetectionType }) => this.setState({ stableCounter, lastDetectionType })} + detectionCountBeforeCapture={10} + detectionRefreshRateInMS={50} style={styles.scanner} /> } - This is a great example of react-native-pdf-scanner 🤗 + ({this.state.stableCounter || 0} correctly formated rectangle detected + + + {this.renderDetectionType()} {this.state.image === null ? null : diff --git a/Example/ios/Example.xcodeproj/project.pbxproj b/Example/ios/Example.xcodeproj/project.pbxproj index efef4ba..25fa144 100644 --- a/Example/ios/Example.xcodeproj/project.pbxproj +++ b/Example/ios/Example.xcodeproj/project.pbxproj @@ -229,6 +229,13 @@ remoteGlobalIDString = 58B5119B1A9E6C1200147676; remoteInfo = RCTText; }; + D2D661241F1F336E0008DBCE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D2D661051F1F336E0008DBCE /* RNPdfScanner.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 134814201AA4EA6300B7C361; + remoteInfo = RNPdfScanner; + }; D2EF802A1EFD1271008AB871 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; @@ -279,6 +286,7 @@ 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; + D2D661051F1F336E0008DBCE /* RNPdfScanner.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNPdfScanner.xcodeproj; path = ../../ios/RNPdfScanner.xcodeproj; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -463,6 +471,7 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( + D2D661051F1F336E0008DBCE /* RNPdfScanner.xcodeproj */, 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, @@ -511,6 +520,14 @@ name = Products; sourceTree = ""; }; + D2D661061F1F336E0008DBCE /* Products */ = { + isa = PBXGroup; + children = ( + D2D661251F1F336E0008DBCE /* libRNPdfScanner.a */, + ); + name = Products; + sourceTree = ""; + }; D2EF800D1EFD1271008AB871 /* Products */ = { isa = PBXGroup; children = ( @@ -680,6 +697,10 @@ ProductGroup = 146834001AC3E56700842450 /* Products */; ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */; }, + { + ProductGroup = D2D661061F1F336E0008DBCE /* Products */; + ProjectRef = D2D661051F1F336E0008DBCE /* RNPdfScanner.xcodeproj */; + }, { ProductGroup = D2EF800D1EFD1271008AB871 /* Products */; ProjectRef = 29D3F134BEE343FFABB02DE4 /* RNPdfScanner.xcodeproj */; @@ -871,6 +892,13 @@ remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + D2D661251F1F336E0008DBCE /* libRNPdfScanner.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libRNPdfScanner.a; + remoteRef = D2D661241F1F336E0008DBCE /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; D2EF802B1EFD1271008AB871 /* libthird-party.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme b/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme index 273f724..8610f44 100644 --- a/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +++ b/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme @@ -80,7 +80,7 @@ ); } @@ -23,11 +33,14 @@ class PdfScanner extends React.Component { PdfScanner.propTypes = { onPictureTaken: PropTypes.func, + onRectangleDetect: PropTypes.func, overlayColor: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), enableTorch: PropTypes.bool, saturation: PropTypes.number, brightness: PropTypes.number, contrast: PropTypes.number, + detectionCountBeforeCapture: PropTypes.number, + detectionRefreshRateInMS: PropTypes.number, }; export default PdfScanner; diff --git a/ios/DocumentScannerView.h b/ios/DocumentScannerView.h index c0f2ed2..94d8f43 100644 --- a/ios/DocumentScannerView.h +++ b/ios/DocumentScannerView.h @@ -12,7 +12,9 @@ @interface DocumentScannerView : IPDFCameraViewController @property (nonatomic, copy) RCTBubblingEventBlock onPictureTaken; - +@property (nonatomic, copy) RCTBubblingEventBlock onRectangleDetect; +@property (nonatomic, assign) NSInteger detectionCountBeforeCapture; +@property (assign, nonatomic) NSInteger stableCounter; @end diff --git a/ios/DocumentScannerView.m b/ios/DocumentScannerView.m index d0ae8a6..2cbe7e8 100644 --- a/ios/DocumentScannerView.m +++ b/ios/DocumentScannerView.m @@ -9,11 +9,6 @@ #import "DocumentScannerView.h" #import "IPDFCameraViewController.h" -@interface DocumentScannerView() -@property (assign, nonatomic) NSInteger stableCounter; -@end - - @implementation DocumentScannerView - (instancetype)init { @@ -29,9 +24,12 @@ - (instancetype)init { [self setContrast: self.contrast]; [self setBrightness: self.brightness]; [self setSaturation: self.saturation]; - - [self setDelegate: self]; + + NSLog(@"detectionCountBeforeCapture: %ld", (long)self.detectionCountBeforeCapture); + NSLog(@"detectionRefreshRateInMS: %ld", (long)self.detectionRefreshRateInMS); + [self start]; + [self setDelegate: self]; } return self; @@ -47,7 +45,11 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan self.stableCounter = 0; break; } - if (self.stableCounter > 5){ + if (self.onRectangleDetect) { + self.onRectangleDetect(@{@"stableCounter": @(self.stableCounter), @"lastDetectionType": @(type)}); + } + + if (self.stableCounter > self.detectionCountBeforeCapture){ [self captureImageWithCompletionHander:^(id data) { if (self.onPictureTaken) { NSData *imageData = UIImagePNGRepresentation(data); diff --git a/ios/IPDFCameraViewController.h b/ios/IPDFCameraViewController.h index 6d3400d..2ef3529 100644 --- a/ios/IPDFCameraViewController.h +++ b/ios/IPDFCameraViewController.h @@ -49,6 +49,7 @@ typedef NS_ENUM(NSInteger, IPDFRectangeType) @property (nonatomic, assign) float saturation; @property (nonatomic, assign) float contrast; @property (nonatomic, assign) float brightness; +@property (nonatomic, assign) NSInteger detectionRefreshRateInMS; @end diff --git a/ios/IPDFCameraViewController.m b/ios/IPDFCameraViewController.m index 67fdfb3..66352e5 100644 --- a/ios/IPDFCameraViewController.m +++ b/ios/IPDFCameraViewController.m @@ -24,6 +24,7 @@ @interface IPDFCameraViewController ()