feat: Code Scanner API (#1912)
* feat: CodeScanner JS API * feat: iOS * Use guard * Format * feat: Android base * fix: Attach Surfaces * Use isBusy var * fix: Use separate Queue * feat: Finish iOS types * feat: Implement all other code types on Android * fix: Call JS event * fix: Pass codetypes on Android * fix: iOS use Preview coordinate system * docs: Add comments * chore: Format code * Update CameraView+AVCaptureSession.swift * docs: Add Code Scanner docs * docs: Update * feat: Use lazily downloaded model on Android * Revert changes in CameraPage * Format * fix: Fix empty QR codes * Update README.md
This commit is contained in:
45
package/ios/Types/CodeScanner.swift
Normal file
45
package/ios/Types/CodeScanner.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// CodeScanner.swift
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 03.10.23.
|
||||
// Copyright © 2023 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
|
||||
class CodeScanner {
|
||||
let codeTypes: [AVMetadataObject.ObjectType]
|
||||
let interval: Int
|
||||
let regionOfInterest: CGRect?
|
||||
|
||||
init(fromJsValue dictionary: NSDictionary) throws {
|
||||
if let codeTypes = dictionary["codeTypes"] as? [String] {
|
||||
self.codeTypes = try codeTypes.map { value in
|
||||
return try AVMetadataObject.ObjectType(withString: value)
|
||||
}
|
||||
} else {
|
||||
throw CameraError.parameter(.invalidCombination(provided: "codeScanner", missing: "codeTypes"))
|
||||
}
|
||||
|
||||
if let interval = dictionary["interval"] as? Double {
|
||||
self.interval = Int(interval)
|
||||
} else {
|
||||
interval = 300
|
||||
}
|
||||
|
||||
if let regionOfInterest = dictionary["regionOfInterest"] as? NSDictionary {
|
||||
guard let x = regionOfInterest["x"] as? Double,
|
||||
let y = regionOfInterest["y"] as? Double,
|
||||
let width = regionOfInterest["width"] as? Double,
|
||||
let height = regionOfInterest["height"] as? Double else {
|
||||
throw CameraError.parameter(.invalid(unionName: "regionOfInterest", receivedValue: regionOfInterest.description))
|
||||
}
|
||||
|
||||
self.regionOfInterest = CGRect(x: x, y: y, width: width, height: height)
|
||||
} else {
|
||||
regionOfInterest = nil
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user