From 6cc8fefc6f8550557ae4a5ef77cb56bd46f0201a Mon Sep 17 00:00:00 2001 From: James Wang Date: Thu, 27 Feb 2020 13:50:32 +1100 Subject: [PATCH 1/6] add aupport for limiting scan area for Android --- .../reactnative/camera/CameraViewManager.java | 22 +++++ .../org/reactnative/camera/RNCameraView.java | 24 +++++- .../camera/tasks/BarCodeScannerAsyncTask.java | 82 +++++++++++++++++-- 3 files changed, 119 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/org/reactnative/camera/CameraViewManager.java b/android/src/main/java/org/reactnative/camera/CameraViewManager.java index 38b6cafc9..4c557416e 100644 --- a/android/src/main/java/org/reactnative/camera/CameraViewManager.java +++ b/android/src/main/java/org/reactnative/camera/CameraViewManager.java @@ -200,4 +200,26 @@ public void setGoogleVisionBarcodeMode(RNCameraView view, int barcodeMode) { public void setTextRecognizing(RNCameraView view, boolean textRecognizerEnabled) { view.setShouldRecognizeText(textRecognizerEnabled); } + + /**---limit scan area addition---**/ + @ReactProp(name = "rectOfInterest") + public void setRectOfInterest(RNCameraView view, ReadableMap coordinates) { + if(coordinates != null){ + float x = (float) coordinates.getDouble("x"); + float y = (float) coordinates.getDouble("y"); + float width = (float) coordinates.getDouble("width"); + float height = (float) coordinates.getDouble("height"); + view.setRectOfInterest(x, y, width, height); + } + } + + @ReactProp(name = "cameraViewDimensions") + public void setCameraViewDimensions(RNCameraView view, ReadableMap dimensions) { + if(dimensions != null){ + int cameraViewWidth = (int) dimensions.getDouble("width"); + int cameraViewHeight = (int) dimensions.getDouble("height"); + view.setCameraViewDimensions(cameraViewWidth, cameraViewHeight); + } + } + /**---limit scan area addition---**/ } diff --git a/android/src/main/java/org/reactnative/camera/RNCameraView.java b/android/src/main/java/org/reactnative/camera/RNCameraView.java index 013c0a849..0abd32417 100644 --- a/android/src/main/java/org/reactnative/camera/RNCameraView.java +++ b/android/src/main/java/org/reactnative/camera/RNCameraView.java @@ -67,6 +67,15 @@ public class RNCameraView extends CameraView implements LifecycleEventListener, private int mPaddingX; private int mPaddingY; + // Limit Android Scan Area + private boolean mLimitScanArea = false; + private float mScanAreaX = 0.0f; + private float mScanAreaY = 0.0f; + private float mScanAreaWidth = 0.0f; + private float mScanAreaHeight = 0.0f; + private int mCameraViewWidth = 0; + private int mCameraViewHeight = 0; + public RNCameraView(ThemedReactContext themedReactContext) { super(themedReactContext, true); mThemedReactContext = themedReactContext; @@ -152,7 +161,7 @@ public void onFramePreview(CameraView cameraView, byte[] data, int width, int he if (willCallBarCodeTask) { barCodeScannerTaskLock = true; BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate) cameraView; - new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, data, width, height).execute(); + new BarCodeScannerAsyncTask(delegate, mMultiFormatReader, data, width, height, mLimitScanArea, mScanAreaX, mScanAreaY, mScanAreaWidth, mScanAreaHeight, mCameraViewWidth, mCameraViewHeight, getAspectRatio().toFloat()).execute(); } if (willCallFaceTask) { @@ -356,6 +365,19 @@ public void onBarCodeScanningTaskCompleted() { } } + // Limit Scan Area + public void setRectOfInterest(float x, float y, float width, float height) { + this.mLimitScanArea = true; + this.mScanAreaX = x; + this.mScanAreaY = y; + this.mScanAreaWidth = width; + this.mScanAreaHeight = height; + } + public void setCameraViewDimensions(int width, int height) { + this.mCameraViewWidth = width; + this.mCameraViewHeight = height; + } + /** * Initial setup of the face detector */ diff --git a/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java b/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java index 82dd0276b..8ed731461 100644 --- a/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java +++ b/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java @@ -13,6 +13,14 @@ public class BarCodeScannerAsyncTask extends android.os.AsyncTask Date: Thu, 27 Feb 2020 13:52:57 +1100 Subject: [PATCH 2/6] add types --- types/index.d.ts | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 8aaff4c7f..78e58cbe1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -22,7 +22,7 @@ type Orientation = Readonly<{ }>; type OrientationNumber = 1 | 2 | 3 | 4; type AutoFocus = Readonly<{ on: any; off: any }>; -type VideoStabilization = Readonly<{off: any, standard: any, cinematic: any, auto: any}>; +type VideoStabilization = Readonly<{ off: any, standard: any, cinematic: any, auto: any }>; type FlashMode = Readonly<{ on: any; off: any; torch: any; auto: any }>; type CameraType = Readonly<{ front: any; back: any }>; type WhiteBalance = Readonly<{ @@ -199,6 +199,9 @@ export interface RNCameraProps { barcodes: Barcode[]; }): void; + // limiting scan area + rectOfInterest?: Point; + // -- FACE DETECTION PROPS onFacesDetected?(response: { faces: Face[] }): void; @@ -235,6 +238,9 @@ export interface RNCameraProps { buttonNeutral?: string; } | null; + // limiting scan area, must provide cameraViewDimensions for Android + cameraViewDimensions?: Object; + // -- IOS ONLY PROPS videoStabilizationMode?: keyof VideoStabilization; defaultVideoQuality?: keyof VideoQuality; @@ -272,9 +278,9 @@ export interface Barcode { firstName?: string; lastName?: string; middleName?: string; - prefix?:string; - pronounciation?:string; - suffix?:string; + prefix?: string; + pronounciation?: string; + suffix?: string; formattedName?: string; }; phone?: Phone; @@ -313,18 +319,18 @@ export interface Barcode { } export type BarcodeType = - |"EMAIL" - |"PHONE" - |"CALENDAR_EVENT" - |"DRIVER_LICENSE" - |"GEO" - |"SMS" - |"CONTACT_INFO" - |"WIFI" - |"TEXT" - |"ISBN" - |"PRODUCT" - |"URL" + | "EMAIL" + | "PHONE" + | "CALENDAR_EVENT" + | "DRIVER_LICENSE" + | "GEO" + | "SMS" + | "CONTACT_INFO" + | "WIFI" + | "TEXT" + | "ISBN" + | "PRODUCT" + | "URL" export interface Email { address?: string; From 3f66aa5aebd64bbf0dcaf646a7c0118d5119f5c4 Mon Sep 17 00:00:00 2001 From: James Wang Date: Thu, 27 Feb 2020 13:59:19 +1100 Subject: [PATCH 3/6] update RNcamera readme --- docs/RNCamera.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/RNCamera.md b/docs/RNCamera.md index 956173862..ff48a04cf 100644 --- a/docs/RNCamera.md +++ b/docs/RNCamera.md @@ -324,10 +324,17 @@ By default a `Camera not authorized` message will be displayed when access to th By default a will be displayed while the component is waiting for the user to grant/deny access to the camera, if set displays the passed react element instead of the default one. -#### `iOS` `rectOfInterest` +#### `rectOfInterest` An `{x: , y:, width:, height: }` object which defines the rect of interst as normalized coordinates from `(0,0)` top left corner to `(1,1)` bottom right corner. +Note: Must also provide cameraViewDimensions prop for Android device + +### `Android` `cameraViewDimensions` + +An `{width:, height: }` object which defines the width and height of the cameraView. This prop is used to adjust the effect of Aspect Raio for rectOfInterest area on Android + + ### `iOS` `videoStabilizationMode` The video stabilization mode used for a video recording. The possible values are: From 398ac120fcce5bdcca5402b0ba4bf66a3d306dc9 Mon Sep 17 00:00:00 2001 From: James Wang Date: Thu, 27 Feb 2020 14:01:53 +1100 Subject: [PATCH 4/6] fix typo --- .../org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java b/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java index 8ed731461..5a1f9bad3 100644 --- a/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java +++ b/android/src/main/java/org/reactnative/camera/tasks/BarCodeScannerAsyncTask.java @@ -48,8 +48,8 @@ public BarCodeScannerAsyncTask( mScanAreaY = scanAreaY; mScanAreaWidth = scanAreaWidth; mScanAreaHeight = scanAreaHeight; - mCameraWidth = cameraViewWidth; - mCameraHeight = cameraViewHeight; + mCameraViewWidth = cameraViewWidth; + mCameraViewHeight = cameraViewHeight; mRatio = ratio; } From 3f801ee11cd9eeff6856047115595ea4ab37a674 Mon Sep 17 00:00:00 2001 From: James Wang Date: Sat, 29 Feb 2020 17:42:35 +1100 Subject: [PATCH 5/6] add example --- examples/rectOfInterest/.buckconfig | 6 + examples/rectOfInterest/.eslintrc.js | 4 + examples/rectOfInterest/.flowconfig | 75 + examples/rectOfInterest/.gitattributes | 1 + examples/rectOfInterest/.gitignore | 59 + examples/rectOfInterest/.prettierrc.js | 6 + examples/rectOfInterest/.watchmanconfig | 1 + examples/rectOfInterest/App.js | 90 + examples/rectOfInterest/__tests__/App-test.js | 14 + examples/rectOfInterest/android/app/BUCK | 55 + .../rectOfInterest/android/app/build.gradle | 202 + .../rectOfInterest/android/app/build_defs.bzl | 19 + .../rectOfInterest/android/app/debug.keystore | Bin 0 -> 2257 bytes .../android/app/proguard-rules.pro | 10 + .../android/app/src/debug/AndroidManifest.xml | 8 + .../android/app/src/main/AndroidManifest.xml | 26 + .../java/com/rectofinterest/MainActivity.java | 15 + .../com/rectofinterest/MainApplication.java | 74 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 9 + examples/rectOfInterest/android/build.gradle | 38 + .../rectOfInterest/android/gradle.properties | 21 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 55616 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + examples/rectOfInterest/android/gradlew | 188 + examples/rectOfInterest/android/gradlew.bat | 100 + .../rectOfInterest/android/settings.gradle | 3 + examples/rectOfInterest/app.json | 4 + examples/rectOfInterest/babel.config.js | 3 + examples/rectOfInterest/index.js | 9 + examples/rectOfInterest/ios/Podfile | 53 + examples/rectOfInterest/ios/Podfile.lock | 350 + .../ios/rectOfInterest-tvOS/Info.plist | 53 + .../ios/rectOfInterest-tvOSTests/Info.plist | 24 + .../rectOfInterest.xcodeproj/project.pbxproj | 922 ++ .../xcschemes/rectOfInterest-tvOS.xcscheme | 129 + .../xcschemes/rectOfInterest.xcscheme | 129 + .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../ios/rectOfInterest/AppDelegate.h | 15 + .../ios/rectOfInterest/AppDelegate.m | 42 + .../Base.lproj/LaunchScreen.xib | 42 + .../AppIcon.appiconset/Contents.json | 38 + .../Images.xcassets/Contents.json | 6 + .../ios/rectOfInterest/Info.plist | 59 + .../rectOfInterest/ios/rectOfInterest/main.m | 16 + .../ios/rectOfInterestTests/Info.plist | 24 + .../rectOfInterestTests/rectOfInterestTests.m | 72 + examples/rectOfInterest/metro.config.js | 17 + examples/rectOfInterest/package-lock.json | 8611 +++++++++++++++++ examples/rectOfInterest/package.json | 30 + 61 files changed, 11698 insertions(+) create mode 100644 examples/rectOfInterest/.buckconfig create mode 100644 examples/rectOfInterest/.eslintrc.js create mode 100644 examples/rectOfInterest/.flowconfig create mode 100644 examples/rectOfInterest/.gitattributes create mode 100644 examples/rectOfInterest/.gitignore create mode 100644 examples/rectOfInterest/.prettierrc.js create mode 100644 examples/rectOfInterest/.watchmanconfig create mode 100644 examples/rectOfInterest/App.js create mode 100644 examples/rectOfInterest/__tests__/App-test.js create mode 100644 examples/rectOfInterest/android/app/BUCK create mode 100644 examples/rectOfInterest/android/app/build.gradle create mode 100644 examples/rectOfInterest/android/app/build_defs.bzl create mode 100644 examples/rectOfInterest/android/app/debug.keystore create mode 100644 examples/rectOfInterest/android/app/proguard-rules.pro create mode 100644 examples/rectOfInterest/android/app/src/debug/AndroidManifest.xml create mode 100644 examples/rectOfInterest/android/app/src/main/AndroidManifest.xml create mode 100644 examples/rectOfInterest/android/app/src/main/java/com/rectofinterest/MainActivity.java create mode 100644 examples/rectOfInterest/android/app/src/main/java/com/rectofinterest/MainApplication.java create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 examples/rectOfInterest/android/app/src/main/res/values/strings.xml create mode 100644 examples/rectOfInterest/android/app/src/main/res/values/styles.xml create mode 100644 examples/rectOfInterest/android/build.gradle create mode 100644 examples/rectOfInterest/android/gradle.properties create mode 100644 examples/rectOfInterest/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 examples/rectOfInterest/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 examples/rectOfInterest/android/gradlew create mode 100644 examples/rectOfInterest/android/gradlew.bat create mode 100644 examples/rectOfInterest/android/settings.gradle create mode 100644 examples/rectOfInterest/app.json create mode 100644 examples/rectOfInterest/babel.config.js create mode 100644 examples/rectOfInterest/index.js create mode 100644 examples/rectOfInterest/ios/Podfile create mode 100644 examples/rectOfInterest/ios/Podfile.lock create mode 100644 examples/rectOfInterest/ios/rectOfInterest-tvOS/Info.plist create mode 100644 examples/rectOfInterest/ios/rectOfInterest-tvOSTests/Info.plist create mode 100644 examples/rectOfInterest/ios/rectOfInterest.xcodeproj/project.pbxproj create mode 100644 examples/rectOfInterest/ios/rectOfInterest.xcodeproj/xcshareddata/xcschemes/rectOfInterest-tvOS.xcscheme create mode 100644 examples/rectOfInterest/ios/rectOfInterest.xcodeproj/xcshareddata/xcschemes/rectOfInterest.xcscheme create mode 100644 examples/rectOfInterest/ios/rectOfInterest.xcworkspace/contents.xcworkspacedata create mode 100644 examples/rectOfInterest/ios/rectOfInterest.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 examples/rectOfInterest/ios/rectOfInterest/AppDelegate.h create mode 100644 examples/rectOfInterest/ios/rectOfInterest/AppDelegate.m create mode 100644 examples/rectOfInterest/ios/rectOfInterest/Base.lproj/LaunchScreen.xib create mode 100644 examples/rectOfInterest/ios/rectOfInterest/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 examples/rectOfInterest/ios/rectOfInterest/Images.xcassets/Contents.json create mode 100644 examples/rectOfInterest/ios/rectOfInterest/Info.plist create mode 100644 examples/rectOfInterest/ios/rectOfInterest/main.m create mode 100644 examples/rectOfInterest/ios/rectOfInterestTests/Info.plist create mode 100644 examples/rectOfInterest/ios/rectOfInterestTests/rectOfInterestTests.m create mode 100644 examples/rectOfInterest/metro.config.js create mode 100644 examples/rectOfInterest/package-lock.json create mode 100644 examples/rectOfInterest/package.json diff --git a/examples/rectOfInterest/.buckconfig b/examples/rectOfInterest/.buckconfig new file mode 100644 index 000000000..934256cb2 --- /dev/null +++ b/examples/rectOfInterest/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/examples/rectOfInterest/.eslintrc.js b/examples/rectOfInterest/.eslintrc.js new file mode 100644 index 000000000..40c6dcd05 --- /dev/null +++ b/examples/rectOfInterest/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native-community', +}; diff --git a/examples/rectOfInterest/.flowconfig b/examples/rectOfInterest/.flowconfig new file mode 100644 index 000000000..4afc766a2 --- /dev/null +++ b/examples/rectOfInterest/.flowconfig @@ -0,0 +1,75 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore polyfills +node_modules/react-native/Libraries/polyfills/.* + +; These should not be required directly +; require from fbjs/lib instead: require('fbjs/lib/warning') +node_modules/warning/.* + +; Flow doesn't support platforms +.*/Libraries/Utilities/LoadingView.js + +[untyped] +.*/node_modules/@react-native-community/cli/.*/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ + +[options] +emoji=true + +esproposal.optional_chaining=enable +esproposal.nullish_coalescing=enable + +module.file_ext=.js +module.file_ext=.json +module.file_ext=.ios.js + +munge_underscores=true + +module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation' +module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' +module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[lints] +sketchy-null-number=warn +sketchy-null-mixed=warn +sketchy-number=warn +untyped-type-import=warn +nonstrict-import=warn +deprecated-type=warn +unsafe-getters-setters=warn +inexact-spread=warn +unnecessary-invariant=warn +signature-verification-failure=warn +deprecated-utility=error + +[strict] +deprecated-type +nonstrict-import +sketchy-null +unclear-type +unsafe-getters-setters +untyped-import +untyped-type-import + +[version] +^0.105.0 diff --git a/examples/rectOfInterest/.gitattributes b/examples/rectOfInterest/.gitattributes new file mode 100644 index 000000000..d42ff1835 --- /dev/null +++ b/examples/rectOfInterest/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/examples/rectOfInterest/.gitignore b/examples/rectOfInterest/.gitignore new file mode 100644 index 000000000..ad572e632 --- /dev/null +++ b/examples/rectOfInterest/.gitignore @@ -0,0 +1,59 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore +!debug.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle + +# CocoaPods +/ios/Pods/ diff --git a/examples/rectOfInterest/.prettierrc.js b/examples/rectOfInterest/.prettierrc.js new file mode 100644 index 000000000..5c4de1a4f --- /dev/null +++ b/examples/rectOfInterest/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + bracketSpacing: false, + jsxBracketSameLine: true, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/examples/rectOfInterest/.watchmanconfig b/examples/rectOfInterest/.watchmanconfig new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/examples/rectOfInterest/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/examples/rectOfInterest/App.js b/examples/rectOfInterest/App.js new file mode 100644 index 000000000..646812203 --- /dev/null +++ b/examples/rectOfInterest/App.js @@ -0,0 +1,90 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + * + * @format + * @flow + */ + +import React, { useCallback, useState } from 'react'; +import { + View, + Dimensions, + Button, + Text +} from 'react-native'; + +import { RNCamera } from 'react-native-camera'; + +const App: () => React$Node = () => { + const [showCamera, setShowCamera] = useState(); + + const CAM_VIEW_HEIGHT = 600; + const CAM_VIEW_WIDTH = Dimensions.get('screen').width; + + // The following are based on landscape orientation with home button to the right + + // left + const leftMargin = 100; + // top + const topMargin = 50; + // width (height of portrait orientation) + const frameWidth = 200; + // height (width of portrait orientation) + const frameHeight = 250; + + const scanAreaX = leftMargin / CAM_VIEW_HEIGHT; + const scanAreaY = topMargin / CAM_VIEW_WIDTH; + const scanAreaWidth = frameWidth / CAM_VIEW_HEIGHT; + const scanAreaHeight = frameHeight / CAM_VIEW_WIDTH; + + + const onBarCodeRead = useCallback((result) => { + if (result) { + const { type, data } = result; + if (data) { + console.log('code detected', data); + } + } + }, []); + + return ( + +