Custom navigation swiftui NavigationLink NavigationView

Last update: Jun 9, 2022

Custom navigation swiftui

Experimenting with navigation link. if you find this idea interesting you can take and expend it into a more powerful solution. Live youtube

The result navigaion

    @State var route : Router = .empty

    var body: some View {
        NavigationView{
            VStack{
                Button("go1") { route = .go1}
                Button("go2") { route = .go2}
                Button("go3") { route = .go3}
            }.navigation(route: $route)
            
        }.navigationViewStyle(.stack)
    }

1. Define sub view

struct SubView: View {

    let text: String

    var body: some View {
        Text("\(text)")
    }
}

2. Define routes

enum Router {
    case go1
    case go2
    case go3
    case empty

    @ViewBuilder
    var builder: some View {
        switch(self) {
            case .go1: SubView(text: "go1")
            case .go2: SubView(text: "go2")
            case .go3: SubView(text: "go3")
        default: EmptyView()
        }
    }
}

3. Define view modifire

struct NavigationModifire : ViewModifier{
    
    @State var isActive :  Bool = true
    
    @Binding var route : Router
    
    func body(content: Content) -> some View {
        content
            .background{
                NavigationLink(destination : route.builder, isActive: $isActive ){
                    EmptyView()
                }.hidden()
            }
            .onChange(of: isActive){
                if $0 == false { route = .empty }
            }
    }
    
}

extension View{
    @ViewBuilder
    func navigation(route : Binding) -> some View{
        if route.wrappedValue != .empty{
            modifier(NavigationModifire(route: route))
        }else { self }
    }
}

GitHub

https://github.com/The-Igor/d3-custom-navigation-swiftui
You might also like...

Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

Tools for making SwiftUI navigation simpler, more ergonomic and more precise.

SwiftUI Navigation Tools for making SwiftUI navigation simpler, more ergonomic and more precise. Motivation Tools Navigation overloads Navigation view

Jun 16, 2022

SwiftUINavigation provides UIKit-like navigation in SwiftUI

SwiftUINavigation About SwiftUINavigation provides UIKit-like navigation in Swif

Mar 28, 2022

A lightweight iOS mini framework that enables programmatic navigation with SwiftUI, by using UIKit under the hood.

RouteLinkKit A lightweight iOS mini framework that enables programmatic navigation with SwiftUI. RouteLinkKit is fully compatible with native Navigati

Feb 8, 2022

SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❤️ by Mahmoud Hussein SwiftUINavigator is a lightwe

Jun 7, 2022

Simple iOS app to showcase navigation with coordinators in SwiftUI + MVVM.

Simple iOS app to showcase navigation with coordinators in SwiftUI + MVVM.

SimpleNavigation Simple iOS app to showcase the use of the Coordinator pattern using SwiftUI and MVVM. The implementation is as easy as calling a push

Apr 24, 2022

Models UI navigation patterns using TCA

Composable Navigation The Composable Navigation is a Swift Package that builds on top of The Composable Architecture (TCA, for short). It models UI na

Jun 25, 2022

An iOS view-controller navigation management. No inherit, using one line code to integrate.

An iOS view-controller navigation management. No inherit, using one line code to integrate.

KGNavigationBar Example An iOS view-controller navigation management. No inherit, using one line code to integrate. 一个 iOS 控制器导航管理库. 无需继承, 一行代码即可实现集成。

Sep 6, 2021

Powerful navigation in the Composable Architecture via the coordinator pattern

TCACoordinators The coordinator pattern in the Composable Architecture TCACoordinators brings a flexible approach to navigation in SwiftUI using the C

Jun 27, 2022

Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Launch Navigator Cordova/Phonegap Plugin Cordova/Phonegap plugin for launching today's most popular navigation/ride apps to navigate to a destination.

Oct 25, 2021
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.

swiftui-navigation-stack An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations

Jun 27, 2022
NavigationViewKit is a NavigationView extension library for SwiftUI.

NavigationViewKit 中文版说明 NavigationViewKit is a NavigationView extension library for SwiftUI. For more detailed documentation and demo, please visit 用N

Jun 21, 2022
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Jun 12, 2022
Simple custom navigation bar by swift

YoNavBarView Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation YoNav

Nov 23, 2021
sRouting - The lightweight navigation framework for SwiftUI.
sRouting - The lightweight navigation framework for SwiftUI.

sRouting The lightweight navigation framework for SwiftUI. Overview sRouting using the native navigation mechanism in SwiftUI. It's easy to handle nav

Apr 14, 2022
FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator

FlowStacks allow you to manage complex SwiftUI navigation and presentation flows with a single piece of state. This makes it easy to hoist that state into a high-level coordinator view. Using this pattern, you can write isolated views that have zero knowledge of their context within the navigation flow of an app.

Jun 24, 2022
Change SwiftUI Navigation Bar Color for different View
Change SwiftUI Navigation Bar Color for different View

SwiftUINavigationBarColor Change SwiftUI NavigationBar background color per screen. Usage For NavigationBarColor to work, you have to set the Navigati

Jun 11, 2022
🧭 SwiftUI navigation done right

?? NavigationKit NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. ?? Installation ?? Swift Package Manager Usi

Jun 8, 2022
Navigation helpers for SwiftUI applications build with ComposableArchitecture
Navigation helpers for SwiftUI applications build with ComposableArchitecture

Swift Composable Presentation ?? Description Navigation helpers for SwiftUI applications build with ComposableArchitecture. More info about the concep

Apr 23, 2022
Make SwiftUI Navigation be easy

VNavigator VNavigator is a clean and easy-to-use navigation in SwiftUI base on UINavigationController in UIKit Installation From CocoaPods CocoaPods i

Feb 17, 2022