UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

CodeScanner - StackNaviagtionViewStyle is breaking the Navigation link.

Forums > SwiftUI

Hello,

I'm trying to use CodeScanner(twostraws github with a navigation link. I can get it to work, however when I add .navigationViewStyle(StackNavigationViewStyle()) to NavigationView it scans and shows the next view however the next time I scan a code it scans it but just goes back to the menu.

I am using StackNavigationViewStyle Becuse I dont want the menu split screen on the iPad.

Any ideas how to fix this?

Thank you,

Cameron


import SwiftUI
import CodeScanner

struct ContentView: View {

    @State var isPresentingScanner = false
    @State var scannedCode: String?

    var body: some View {
        NavigationView {
            VStack(spacing: 10) {
                if self.scannedCode != nil {
                    NavigationLink("Next page", destination: NextView2(scannedCode: scannedCode!), isActive: .constant(true)).hidden()
                }
                Button("Scan Code") {
                    self.isPresentingScanner = true

                }
                .sheet(isPresented: $isPresentingScanner) {
                    self.scannerSheet
                }
                Text("Scan QR code")
            }

        }.navigationViewStyle(StackNavigationViewStyle())
    }

    struct NextView2: View {
        var scannedCode: String

        var body: some View {
            Text("Your code is: \(scannedCode)")
        }
    }

    var scannerSheet : some View {
        CodeScannerView(
            codeTypes: [.qr],
            completion: { result in
                if case let .success(code) = result {
                    self.scannedCode = code
                    self.isPresentingScanner = false
                }
            }
        )
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.