@@ -85,12 +85,17 @@ public struct CodeScannerView: UIViewControllerRepresentable {
8585 public let requiresPhotoOutput : Bool
8686 public var simulatedData = " "
8787 public var shouldVibrateOnSuccess : Bool
88- public var isTorchOn : Bool
88+ public var torchMode : AVCaptureDevice . TorchMode
8989 public var isPaused : Bool
9090 public var isGalleryPresented : Binding < Bool >
9191 public var videoCaptureDevice : AVCaptureDevice ?
9292 public var completion : ( Result < ScanResult , ScanError > ) -> Void
9393
94+ public var isTorchOn : Bool {
95+ get { torchMode == . on }
96+ set { torchMode = newValue ? . on : . off }
97+ }
98+
9499 public init (
95100 codeTypes: [ AVMetadataObject . ObjectType ] ,
96101 scanMode: ScanMode = . once,
@@ -101,6 +106,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
101106 simulatedData: String = " " ,
102107 shouldVibrateOnSuccess: Bool = true ,
103108 isTorchOn: Bool = false ,
109+ torchMode: AVCaptureDevice . TorchMode ? = nil ,
104110 isPaused: Bool = false ,
105111 isGalleryPresented: Binding < Bool > = . constant( false ) ,
106112 videoCaptureDevice: AVCaptureDevice ? = AVCaptureDevice . bestForVideo,
@@ -114,7 +120,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
114120 self . scanInterval = scanInterval
115121 self . simulatedData = simulatedData
116122 self . shouldVibrateOnSuccess = shouldVibrateOnSuccess
117- self . isTorchOn = isTorchOn
123+ self . torchMode = torchMode ?? ( isTorchOn ? . on : . off )
118124 self . isPaused = isPaused
119125 self . isGalleryPresented = isGalleryPresented
120126 self . videoCaptureDevice = videoCaptureDevice
@@ -128,7 +134,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
128134 public func updateUIViewController( _ uiViewController: ScannerViewController , context: Context ) {
129135 uiViewController. parentView = self
130136 uiViewController. updateViewController (
131- isTorchOn : isTorchOn ,
137+ torchMode : torchMode ,
132138 isGalleryPresented: isGalleryPresented. wrappedValue,
133139 isManualCapture: scanMode. isManual,
134140 isManualSelect: manualSelect
0 commit comments