Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

kumarlav0
Copy link

  • When I tried to implement this CodeScanner I found there is no manual button to turn on/off the torch at the time of Scanning QR code.

  • So, On the basis of that I create this branch with manual button on ui to turn on/off torch at the time of Scanning QR code. It is a small feature but it is very useful for users.

  • Previously we have only option to turn on torch at the time of initialisation of CodeScannerView. And due to this flashlight gets automatically on for longer time. Which I found very unknowing feature.

  • If user will have button to turn ON/OFF torch or flashlight at the time of scanning QR code it will be very helpful for them.

  • I hope this could be add on feature for this Code Scanner.

@nathanfallet
Copy link
Collaborator

nathanfallet commented Feb 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants