CodeScanner icon indicating copy to clipboard operation
CodeScanner copied to clipboard

Navigation links stop working after going back from view with Scanner

Open VladLupashevskyi opened this issue 3 years ago • 0 comments

Here is the example:

import SwiftUI
import CodeScanner

struct Example: View {
    @State private var showQr = false
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: QR(), isActive: $showQr) { Text("Click me") }
            }
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct QR: View {
    var body: some View {
        CodeScannerView(
            codeTypes: [.qr],
            completion: {result in }
        )
    }
}

If you click on Click me and then immediately press Back (this might require a couple of tries to reproduce) then suddenly nothing happens after clicking on Click Me, so the app needs to be restarted.

I noticed that I cannot reproduce this behaviour if I remove either isActive from NagivationLink or .navigationViewStyle(StackNavigationViewStyle()).

I believe it's some kind of race happening and also I think I've had bigger chance to reproduce it, because I have iPhone 7 which is slower than newer ones.

I've tried to apply changes mentioned in #31 by @breyed and it fixed the issue on my side.

DispatchQueue.global(qos: .userInitiated).async {
    self.captureSession.startRunning()
}
DispatchQueue.global(qos: .userInitiated).async {
    self.captureSession.stopRunning()
}

VladLupashevskyi avatar Nov 09 '21 19:11 VladLupashevskyi