-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathBarcodeScannerCameraView.swift
More file actions
37 lines (33 loc) · 1.1 KB
/
BarcodeScannerCameraView.swift
File metadata and controls
37 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()
}
}
}