Files
babaevmm 956c055cd8 update swiftformat, add organize rule
commit_hash:0f7ba811b37db6d2a9fc05efe5f94502feda4856
2025-08-04 16:24:48 +03:00

66 lines
1.6 KiB
Swift

import UIKit
import VGSL
final class ScannerViewController: UIViewController {
let result = ObservableProperty(initialValue: "")
private let captureSession: Lazy<MetadataCaptureSession>
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
init(
logError: @escaping LogError
) {
captureSession = Lazy(
onMainThreadGetter: { [result] in
MetadataCaptureSession(
result: result,
logError: logError
)
}
)
super.init(nibName: nil, bundle: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(orientationDidChange),
name: UIDevice.orientationDidChangeNotification,
object: nil
)
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.black
view.layer.addSublayer(captureSession.value.layer)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
captureSession.value.resume()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
captureSession.value.pause()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
CATransaction.begin()
CATransaction.setDisableActions(true)
captureSession.value.layer.frame = view.bounds
CATransaction.commit()
}
@objc private func orientationDidChange() {
let orientation = UIDevice.current.orientation
guard orientation != .portraitUpsideDown else { return }
captureSession.value.didChangeOrientation(to: orientation)
}
}