-
Notifications
You must be signed in to change notification settings - Fork 618
feat: Add forbiddenBarcodeTypes property #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d0bed7
b085a78
cc6d18c
f8be0f0
1ea413a
4cbec39
d42ef62
2a1f06a
ea894d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,11 @@ class CKCameraManager(context: ReactApplicationContext) : SimpleViewManager<CKCa | |
| view.setShutterPhotoSound(enabled); | ||
| } | ||
|
|
||
| @ReactProp(name = "allowedBarcodeTypes") | ||
| override fun setAllowedBarcodeTypes(view: CKCamera, types: ReadableArray?) { | ||
| view.setAllowedBarcodeTypes(types) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to do the conversion to
|
||
| } | ||
|
|
||
| @ReactProp(name = "scanThrottleDelay") | ||
| override fun setScanThrottleDelay(view: CKCamera?, value: Int) { | ||
| view?.setScanThrottleDelay(value) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,6 @@ | |
| // scanner | ||
| private var lastBarcodeDetectedTime: TimeInterval = 0 | ||
| private var scannerInterfaceView: ScannerInterfaceView | ||
| private var supportedBarcodeType: [CodeFormat] = { | ||
| return CodeFormat.allCases | ||
| }() | ||
|
|
||
| // camera | ||
| private var ratioOverlayView: RatioOverlayView? | ||
|
|
@@ -50,6 +47,7 @@ | |
| @objc public var frameColor: UIColor? | ||
| @objc public var laserColor: UIColor? | ||
| @objc public var barcodeFrameSize: NSDictionary? | ||
| @objc public var allowedBarcodeTypes: NSArray? | ||
|
|
||
| // other | ||
| @objc public var onOrientationChange: RCTDirectEventBlock? | ||
|
|
@@ -82,12 +80,14 @@ | |
| } | ||
| private func setupCamera() { | ||
| if hasPropBeenSetup && hasPermissionBeenGranted && !hasCameraBeenSetup { | ||
| let convertedAllowedTypes = convertAllowedBarcodeTypes() | ||
|
|
||
| hasCameraBeenSetup = true | ||
| #if targetEnvironment(macCatalyst) | ||
| // Force front camera on Mac Catalyst during initial setup | ||
| camera.setup(cameraType: .front, supportedBarcodeType: scanBarcode && onReadCode != nil ? supportedBarcodeType : []) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need |
||
| camera.setup(cameraType: .front, supportedBarcodeType: scanBarcode && onReadCode != nil ? convertedAllowedTypes : []) | ||
| #else | ||
| camera.setup(cameraType: cameraType, supportedBarcodeType: scanBarcode && onReadCode != nil ? supportedBarcodeType : []) | ||
| camera.setup(cameraType: cameraType, supportedBarcodeType: scanBarcode && onReadCode != nil ? convertedAllowedTypes : []) | ||
| #endif | ||
| } | ||
| } | ||
|
|
@@ -252,9 +252,11 @@ | |
| } | ||
|
|
||
| // Scanner | ||
| if changedProps.contains("scanBarcode") || changedProps.contains("onReadCode") { | ||
| if changedProps.contains("scanBarcode") || changedProps.contains("onReadCode") || changedProps.contains("allowedBarcodeTypes") { | ||
| let convertedAllowedTypes: [CodeFormat] = convertAllowedBarcodeTypes() | ||
|
|
||
| camera.isBarcodeScannerEnabled(scanBarcode, | ||
| supportedBarcodeTypes: supportedBarcodeType, | ||
| supportedBarcodeTypes: convertedAllowedTypes, | ||
| onBarcodeRead: { [weak self] (barcode, codeFormat) in | ||
| self?.onBarcodeRead(barcode: barcode, codeFormat: codeFormat) | ||
| }) | ||
|
|
@@ -428,7 +430,7 @@ | |
| return temporaryFileURL | ||
| } | ||
|
|
||
| private func onBarcodeRead(barcode: String, codeFormat:CodeFormat) { | ||
| // Throttle barcode detection | ||
| let now = Date.timeIntervalSinceReferenceDate | ||
| guard lastBarcodeDetectedTime + Double(scanThrottleDelay) / 1000 < now else { | ||
|
|
@@ -437,9 +439,17 @@ | |
|
|
||
| lastBarcodeDetectedTime = now | ||
|
|
||
| onReadCode?(["codeStringValue": barcode,"codeFormat":codeFormat.rawValue]) | ||
|
Check warning on line 442 in ios/ReactNativeCameraKit/CameraView.swift
|
||
| } | ||
|
|
||
| private func convertAllowedBarcodeTypes() -> [CodeFormat] { | ||
| guard let allowedTypes = allowedBarcodeTypes as? [String], !allowedTypes.isEmpty else { | ||
| return CodeFormat.allCases | ||
| } | ||
|
|
||
| return allowedTypes.compactMap { CodeFormat(rawValue: $0) } | ||
| } | ||
|
|
||
| // MARK: - Gesture selectors | ||
|
|
||
| @objc func handlePinchToZoomRecognizer(_ pinchRecognizer: UIPinchGestureRecognizer) { | ||
|
|
@@ -450,4 +460,4 @@ | |
| camera.zoomPinchChange(pinchScale: pinchRecognizer.scale) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use Kotlin union?
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/union.html