// // CameraCaptureVC.swift // QuickLocation // import UIKit final class CameraCaptureVC: BaseViewController { override var isNavigationBarHidden: Bool { true } override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent } private let captureMode: CameraCaptureMode private var rootView: CameraCaptureView! var onScan: ((String) -> Void)? var onPhoto: ((UIImage) -> Void)? var onVideo: ((URL) -> Void)? var onOpenAlbum: (() -> Void)? init(mode: CameraCaptureMode) { self.captureMode = mode super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func loadView() { rootView = CameraCaptureView(mode: captureMode) view = rootView } override func viewDidLoad() { super.viewDidLoad() rootView.onClose = { [weak self] in self?.closeCapture() } rootView.onScan = { [weak self] text in self?.onScan?(text) } rootView.onPhoto = { [weak self] image in self?.onPhoto?(image) } rootView.onVideo = { [weak self] url in self?.onVideo?(url) } rootView.onOpenAlbum = { [weak self] in self?.onOpenAlbum?() } } private func closeCapture() { if presentingViewController != nil { dismiss(animated: true) } else { navigationController?.popViewController(animated: true) } } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) rootView.startSession() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) rootView.stopSession() } }