iOS/Sources/App/BarcodeScanner/Camera/BarcodeScannerCameraView.swift
Bruno Pantaleão Gonçalves 62fcf1d60d
Scan barcodes/qrcodes only inside the highlighted area (#3697)
<!-- 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. -->
2025-07-04 16:43:36 +02:00

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()
}
}
}