Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Created November 22, 2024 08:01
Show Gist options
  • Save VAndrJ/63a7df119683426b9c53a8c7cd1161c6 to your computer and use it in GitHub Desktop.
Save VAndrJ/63a7df119683426b9c53a8c7cd1161c6 to your computer and use it in GitHub Desktop.
isPresented navigationDestionation NavigationStack iOS 16 issue.
import SwiftUI
@main
struct NavigationStackIsPresentedMREApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var isFirstScreenPushed = false
var body: some View {
NavigationStack {
Button("Push first") {
isFirstScreenPushed = true
}
.navigationTitle("Root")
.navigationDestination(isPresented: $isFirstScreenPushed) {
FirstScreen(isFirstScreenPushed: $isFirstScreenPushed)
}
}
}
}
struct FirstScreen: View {
@Binding var isFirstScreenPushed: Bool
@State private var isSecondScreenPushed = false
var body: some View {
VStack(spacing: 32) {
Button("Push second") {
isSecondScreenPushed = true
}
Button("Back to root") {
isFirstScreenPushed = false
}
}
.navigationTitle("First")
.navigationDestination(isPresented: $isSecondScreenPushed) {
SecondScreen(
isFirstScreenPushed: $isFirstScreenPushed,
isSecondScreenPushed: $isSecondScreenPushed
)
}
}
}
struct SecondScreen: View {
@Binding var isFirstScreenPushed: Bool
@Binding var isSecondScreenPushed: Bool
var body: some View {
VStack(spacing: 32) {
Button("Back") {
isSecondScreenPushed = false
}
Button("Back to root") {
isFirstScreenPushed = false
}
}
.navigationTitle("Second")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment