Skip to content

Instantly share code, notes, and snippets.

@gahntpo
Last active June 21, 2020 08:09
Show Gist options
  • Select an option

  • Save gahntpo/6442b4dc4342b63e88bf3a9640a5cda3 to your computer and use it in GitHub Desktop.

Select an option

Save gahntpo/6442b4dc4342b63e88bf3a9640a5cda3 to your computer and use it in GitHub Desktop.

Revisions

  1. gahntpo revised this gist Jun 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MainContentView.swift
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ struct FirstView: View {
    Text("Main view")
    .font(.title)
    // binding NavigationLink isAcitve to NavigationController
    NavigationLink(destination: DetailView(), isActive: self.$nav.detailIsShown) {
    NavigationLink(destination: FirstDetailView(), isActive: self.$nav.detailIsShown) {
    Text("show me the details")
    }
    }
  2. gahntpo created this gist Jun 21, 2020.
    45 changes: 45 additions & 0 deletions MainContentView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    import SwiftUI

    struct ContentView: View {

    @EnvironmentObject var nav: NavigationController

    var body: some View {
    // binding TabView selection to NavigationController
    TabView(selection: self.$nav.selection){
    FirstView()
    .tabItem {
    Text("First")
    }.tag(0)

    Text("Second View")
    .font(.title)
    .tabItem {
    Text("Second")

    }.tag(1)
    }
    }
    }

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

    struct FirstView: View {
    @EnvironmentObject var nav: NavigationController
    var body: some View {
    NavigationView {
    VStack {
    Text("Main view")
    .font(.title)
    // binding NavigationLink isAcitve to NavigationController
    NavigationLink(destination: DetailView(), isActive: self.$nav.detailIsShown) {
    Text("show me the details")
    }
    }
    }.navigationViewStyle(StackNavigationViewStyle())
    }
    }