mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-04 11:16:47 -06:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
import SwiftUI
|
|
|
|
struct BarcodeScannerCameraView: View {
|
|
@StateObject private var model: BarcodeScannerDataModel
|
|
private let shouldStartCamera: Bool
|
|
private let screenSize: CGSize
|
|
|
|
init(screenSize: CGSize, model: BarcodeScannerDataModel, shouldStartCamera: Bool = true) {
|
|
self._model = .init(wrappedValue: model)
|
|
self.shouldStartCamera = shouldStartCamera
|
|
self.screenSize = screenSize
|
|
|
|
// If camera shouldn't be started, no need to forward screen size for rect of interest
|
|
if shouldStartCamera {
|
|
model.camera.screenSize = screenSize
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
GeometryReader { geometry in
|
|
if let image = $model.viewfinderImage.wrappedValue {
|
|
image
|
|
.resizable()
|
|
.scaledToFill()
|
|
.frame(width: geometry.size.width, height: geometry.size.height)
|
|
}
|
|
}
|
|
.task {
|
|
if shouldStartCamera {
|
|
await model.camera.start()
|
|
}
|
|
}
|
|
.onDisappear {
|
|
model.stop()
|
|
}
|
|
}
|
|
}
|