react-native-camera-kit/ios/ReactNativeCameraKit/CodeFormat.swift
Imdad Ismail 234e7f89eb
added code format to see type of code scanned (#633)
* added code format to see type of code scanned

* Update ios/ReactNativeCameraKit/SimulatorCamera.swift

Changed supported barcode types to list of CodeFormat

Co-authored-by: David Bertet <11665957+DavidBertet@users.noreply.github.com>

* Update android/src/main/java/com/rncamerakit/CodeFormat.kt

Added annotation for int type

Co-authored-by: David Bertet <11665957+DavidBertet@users.noreply.github.com>

* Added CodeFormat types and fixed an indentation on a function to match other functions

* Replaced AVMetadataObject with CodeFormat in all files

* Updated code format to case Iterable and changed supportedBarcodeType to code format cases

* Update src/Camera.d.ts

---------

Co-authored-by: David Bertet <11665957+DavidBertet@users.noreply.github.com>
Co-authored-by: Seph Soliman <github@seph.dk>
2024-04-30 16:18:00 -07:00

61 lines
1.7 KiB
Swift

//
// CodeFormat.swift
// ReactNativeCameraKit
//
// Created by Imdad on 2023-12-22.
//
import Foundation
import AVFoundation
enum CodeFormat: String, CaseIterable {
case code128 = "code-128"
case code39 = "code-39"
case code93 = "code-93"
case ean13 = "ean-13"
case ean8 = "ean-8"
case itf14 = "itf-14"
case upce = "upc-e"
case qr = "qr"
case pdf417 = "pdf-417"
case aztec = "aztec"
case dataMatrix = "data-matrix"
case unknown = "unknown"
// Convert from AVMetadataObject.ObjectType to CodeFormat
static func fromAVMetadataObjectType(_ type: AVMetadataObject.ObjectType) -> CodeFormat {
switch type {
case .code128: return .code128
case .code39: return .code39
case .code93: return .code93
case .ean13: return .ean13
case .ean8: return .ean8
case .itf14: return .itf14
case .upce: return .upce
case .qr: return .qr
case .pdf417: return .pdf417
case .aztec: return .aztec
case .dataMatrix: return .dataMatrix
default: return .unknown
}
}
// Convert from CodeFormat to AVMetadataObject.ObjectType
func toAVMetadataObjectType() -> AVMetadataObject.ObjectType {
switch self {
case .code128: return .code128
case .code39: return .code39
case .code93: return .code93
case .ean13: return .ean13
case .ean8: return .ean8
case .itf14: return .itf14
case .upce: return .upce
case .qr: return .qr
case .pdf417: return .pdf417
case .aztec: return .aztec
case .dataMatrix: return .dataMatrix
case .unknown: return .init(rawValue: "unknown")
}
}
}