From 2138c0e64eb36d9005968c378e83fc45a1404abf Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Wed, 18 Dec 2024 23:18:19 +0200 Subject: [PATCH] Update example in README.md fixing deprecation warning Fix deprecation "init(_:destination:isActive:)' was deprecated in iOS 16.0: use NavigationLink(value:label:), or navigationDestination(isPresented:destination:), inside a NavigationStack or NavigationSplitView" --- README.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6163c15..660028a 100644 --- a/README.md +++ b/README.md @@ -63,26 +63,29 @@ Here's an example on how to present the QR code-scanning view as a sheet and how struct QRCodeScannerExampleView: View { @State private var isPresentingScanner = false @State private var scannedCode: String? + @State private var navigationPath = NavigationPath() var body: some View { - VStack(spacing: 10) { - if let code = scannedCode { - NavigationLink("Next page", destination: NextView(scannedCode: code), isActive: .constant(true)).hidden() - } + NavigationStack(path: $navigationPath) { + VStack(spacing: 10) { + Button("Scan Code") { + isPresentingScanner = true + } - Button("Scan Code") { - isPresentingScanner = true + Text("Scan a QR code to begin") } - - Text("Scan a QR code to begin") - } - .sheet(isPresented: $isPresentingScanner) { - CodeScannerView(codeTypes: [.qr]) { response in - if case let .success(result) = response { - scannedCode = result.string - isPresentingScanner = false + .sheet(isPresented: $isPresentingScanner) { + CodeScannerView(codeTypes: [.qr]) { response in + if case let .success(result) = response { + scannedCode = result.string + isPresentingScanner = false + navigationPath.append(scannedCode) + } } } + .navigationDestination(for: String.self) { code in + NextView(scannedCode: code) + } } } }