@@ -85,12 +85,17 @@ public struct CodeScannerView: UIViewControllerRepresentable {
85
85
public let requiresPhotoOutput : Bool
86
86
public var simulatedData = " "
87
87
public var shouldVibrateOnSuccess : Bool
88
- public var isTorchOn : Bool
88
+ public var torchMode : AVCaptureDevice . TorchMode
89
89
public var isPaused : Bool
90
90
public var isGalleryPresented : Binding < Bool >
91
91
public var videoCaptureDevice : AVCaptureDevice ?
92
92
public var completion : ( Result < ScanResult , ScanError > ) -> Void
93
93
94
+ public var isTorchOn : Bool {
95
+ get { torchMode == . on }
96
+ set { torchMode = newValue ? . on : . off }
97
+ }
98
+
94
99
public init (
95
100
codeTypes: [ AVMetadataObject . ObjectType ] ,
96
101
scanMode: ScanMode = . once,
@@ -101,6 +106,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
101
106
simulatedData: String = " " ,
102
107
shouldVibrateOnSuccess: Bool = true ,
103
108
isTorchOn: Bool = false ,
109
+ torchMode: AVCaptureDevice . TorchMode ? = nil ,
104
110
isPaused: Bool = false ,
105
111
isGalleryPresented: Binding < Bool > = . constant( false ) ,
106
112
videoCaptureDevice: AVCaptureDevice ? = AVCaptureDevice . bestForVideo,
@@ -114,7 +120,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
114
120
self . scanInterval = scanInterval
115
121
self . simulatedData = simulatedData
116
122
self . shouldVibrateOnSuccess = shouldVibrateOnSuccess
117
- self . isTorchOn = isTorchOn
123
+ self . torchMode = torchMode ?? ( isTorchOn ? . on : . off )
118
124
self . isPaused = isPaused
119
125
self . isGalleryPresented = isGalleryPresented
120
126
self . videoCaptureDevice = videoCaptureDevice
@@ -128,7 +134,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
128
134
public func updateUIViewController( _ uiViewController: ScannerViewController , context: Context ) {
129
135
uiViewController. parentView = self
130
136
uiViewController. updateViewController (
131
- isTorchOn : isTorchOn ,
137
+ torchMode : torchMode ,
132
138
isGalleryPresented: isGalleryPresented. wrappedValue,
133
139
isManualCapture: scanMode. isManual,
134
140
isManualSelect: manualSelect
0 commit comments