Skip to content

Commit

Permalink
Update example in README.md fixing deprecation warning
Browse files Browse the repository at this point in the history
Fix deprecation "init(_:destination:isActive:)' was deprecated in iOS 16.0: use NavigationLink(value:label:), or navigationDestination(isPresented:destination:), inside a NavigationStack or NavigationSplitView"
  • Loading branch information
valeriyvan authored Dec 18, 2024
1 parent 5e88643 commit 2138c0e
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 2138c0e

Please sign in to comment.