Skip to content

Commit

Permalink
Updated code format to case Iterable and changed supportedBarcodeType…
Browse files Browse the repository at this point in the history
… to code format cases
  • Loading branch information
android-imdad committed Feb 22, 2024
1 parent 6579ce3 commit 369dbd7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
15 changes: 6 additions & 9 deletions ios/ReactNativeCameraKit/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class CameraView: UIView {
// scanner
private var lastBarcodeDetectedTime: TimeInterval = 0
private var scannerInterfaceView: ScannerInterfaceView
private var supportedBarcodeType: [AVMetadataObject.ObjectType] = [.upce, .code39, .code39Mod43,
.ean13, .ean8, .code93,
.code128, .pdf417, .qr,
.aztec, .dataMatrix, .interleaved2of5]
private var supportedBarcodeType: [CodeFormat] = {
return CodeFormat.allCases
}()

// camera
private var ratioOverlayView: RatioOverlayView?

Expand Down Expand Up @@ -69,12 +69,10 @@ class CameraView: UIView {
setupCamera()
}
}

private func setupCamera() {
if (hasPropBeenSetup && hasPermissionBeenGranted && !hasCameraBeenSetup) {
hasCameraBeenSetup = true
let supportedFormats = supportedBarcodeType.map { CodeFormat.fromAVMetadataObjectType($0) }
camera.setup(cameraType: cameraType, supportedBarcodeType: scanBarcode && onReadCode != nil ? supportedFormats : [])
camera.setup(cameraType: cameraType, supportedBarcodeType: scanBarcode && onReadCode != nil ? supportedBarcodeType : [])
}
}

Expand Down Expand Up @@ -186,9 +184,8 @@ class CameraView: UIView {

// Scanner
if changedProps.contains("scanBarcode") || changedProps.contains("onReadCode") {
let supportedFormats = supportedBarcodeType.map { CodeFormat.fromAVMetadataObjectType($0) }
camera.isBarcodeScannerEnabled(scanBarcode,
supportedBarcodeTypes: supportedFormats,
supportedBarcodeTypes: supportedBarcodeType,
onBarcodeRead: { [weak self] (barcode, codeFormat) in
self?.onBarcodeRead(barcode: barcode, codeFormat: codeFormat)
})
Expand Down
2 changes: 1 addition & 1 deletion ios/ReactNativeCameraKit/CodeFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import AVFoundation

enum CodeFormat: String {
enum CodeFormat: String, CaseIterable {
case code128 = "code-128"
case code39 = "code-39"
case code93 = "code-93"
Expand Down
6 changes: 4 additions & 2 deletions ios/ReactNativeCameraKit/RealCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,11 @@ class RealCamera: NSObject, CameraProtocol, AVCaptureMetadataOutputObjectsDelega
metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)

let availableTypes = self.metadataOutput.availableMetadataObjectTypes
let filteredTypes = supportedBarcodeType.filter { type in availableTypes.contains(type.toAVMetadataObjectType()) }
let filteredTypes = supportedBarcodeType
.map { $0.toAVMetadataObjectType() }
.filter { availableTypes.contains($0) }

metadataOutput.metadataObjectTypes = filteredTypes.map { $0.toAVMetadataObjectType() }
metadataOutput.metadataObjectTypes = filteredTypes
}

session.commitConfiguration()
Expand Down

0 comments on commit 369dbd7

Please sign in to comment.