twostraws / CodeScanner

A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
MIT License
1.03k stars 295 forks source link

manual torch button added for flashlight at the time of scan QR code #122

Closed kumarlav0 closed 7 months ago

kumarlav0 commented 8 months ago
nathanfallet commented 7 months ago

Your change is breaking the way the library currently works. You cannot remove isTorchOn.

You can implement your own button and inject the value into isTorchOn like this:

    @State var torchIsOn: Bool
    @State var isGalleryPresented: Bool

    var body: some View {
        ZStack {
            CodeScannerView(
                codeTypes: [.qr],
                scanMode: .continuous,
                isTorchOn: torchIsOn,
                isGalleryPresented: $isGalleryPresented,
                completion: { _ in }
            )
            Button(action: { torchIsOn.toggle() }) {
                Image(systemName: torchIsOn ? "bolt.fill" : "bolt.slash.fill")
                    .foregroundColor(torchIsOn ? Color.yellow : Color.accentColor)
            }
        }
    }