Granite (SwiftUI)

GraniteRouter

Swift
struct GraniteRouter: View {
    @EnvironmentObject var routes: GraniteNavigation
    
    var keys: [String]
    
    func isActive(_ id: String) -> Binding<Bool>
    
    var body: some View {
        Group {
            ForEach(Array(routes.stack), id: \.self) { id in
                if let path = routes.paths[id] {
                    path()
                        .environment(\.graniteRouter, routes.asRouter)
                }
            }
        }
        .onAppear {
            GraniteLog("New Stack Appeared: \(routes.id)", level: .debug)
        }
        .onDisappear {
            GraniteLog("Navigation GraniteRouter Disappeared", level: .debug)
        }
    }
}

The GraniteRouter, as seen on the top-most index of the GraniteNavigationView, handles the visibility of active screens in the navigation stack. Very simple approach as since the parent view is a ZStack, these will be simply laid out on top in chronological order of when they are pushed.

The paths themselves are assigned upstream by GraniteNavigation.Router, which connects a target view to its navigation instance.