Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 1.45 KB

README.md

File metadata and controls

62 lines (46 loc) · 1.45 KB

NavigationLink

Our SwiftUI version of UINavigationController.

NavigationView {
    VStack {
        NavigationLink(destination: Text("Detail View")) {
            Text("Hello World")
        }
    }
    .navigationBarTitle("SwiftUI")
}

How to programmatically dismiss

drawing

drawing

  • Bind a @State property to the isActive attribute of NavigationLink
  • Toggle its state in the child detail causing the parent to re-render and stop showing the child view.
import SwiftUI

struct ContentView: View {
    @State private var isShowingDetailView = false
    
    var body: some View {
        NavigationView {
            NavigationLink(destination: DetailView(isShowingDetailView: $isShowingDetailView),
                           isActive: $isShowingDetailView) {
                Text("Detail >")
            }.navigationTitle("Navigation")
        }
    }
}

struct DetailView: View {
    @Binding var isShowingDetailView: Bool
    
    var body: some View {
        Button("Dismiss me") {
            isShowingDetailView.toggle()
        }
    }
}

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

Links that help