A Simple Programmatic Navigation Solution for SwiftUI

Navigator

  • Push Any View

  • Push Any View And Set Navigation Bar Title

  • Pop Back To Specific View ( Navigation Bar Title must be set )

  • Pop Back To Root View

  • Pop Back To Previous View

  • Remove All Views In Stack

  • Set Custom Navigation Stack

    • let viewD = ViewD()
      let viewE = ViewE()
      Navigator.setStack([viewD.getVC(), viewE.getVC()])
      

Example Demo

navigator_demo.mov

Example Usage

import SwiftUI
import Navigator

@main
struct nv_testApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationView {
                ViewA()
            }
        }
    }
}


struct ViewA: View {
    var body: some View {
        Text("Navigate To B")
            .onTapGesture {
                Navigator.push(ViewB())
            }
    }
}


struct ViewB: View {
    var body: some View {
        Text("Navigate To C")
            .onTapGesture {
                Navigator.push(ViewC())
            }
    }
}


struct ViewC: View {
    var body: some View {
        Text("Pop Back To A")
            .onTapGesture {
                Navigator.popToRoot()
            }
    }
}

GitHub

View Github