- July 29, 2025
- Mins Read
NavigationView by Mijick is a powerful, open-source library dedicated for SwiftUI that makes navigation process super easy and much cleaner.
Platforms | Minimum Swift Version |
---|---|
iOS 15+ | 5.0 |
Swift package manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.
Once you have your Swift package set up, adding NavigationView as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: “https://github.com/Mijick/NavigationView”, branch(“main”))
]
Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects that helps to scale them elegantly.
Installation steps:
pod init
Podfile
pod ‘MijickNavigationView’
.xcworkspace
file
pod install
.xcworkspace
Inside your @main
structure, call the implementNavigationView
method with the view that is to be the root of the navigation stack. The view must be of type NavigatableView
. The method takes an optional argument – config
, which can be used to configure certain attributes of all the views that will be placed in the navigation stack.
@main struct NavigationView_Main: App {
var body: some Scene {
WindowGroup {
ContentView()
.implementNavigationView(config: nil)
}
}
}
NavigationView by Mijick provides the ability to push any view conforming to the NavigatableView
protocol to the navigation stack.
struct ExampleView: NavigatableView {
…
}
body
Fill your view with content
struct ExampleView: NavigatableView {
var body: some View {
VStack(spacing: 0) {
Text(“Witaj okrutny świecie”)
Spacer()
Button(action: pop) { Text(“Pop”) }
}
}
…
}
configure(view: NavigationConfig) -> NavigationConfig
methodThis step is optional – if you wish, you can skip this step and leave the configuration as default.
Each view has its own set of methods that can be used to create a unique look for each view in the stack.
struct ExampleView: NavigatableView {
func configure(view: NavigationConfig) -> NavigationConfig { view.backgroundColour(.red) }
var body: some View {
VStack(spacing: 0) {
Text(“Witaj okrutny świecie”)
Spacer()
Button(action: pop) { Text(“Pop”) }
}
}
…
}
Just call ExampleView().push(with:)
from the selected place. As simple as that!
struct SettingsViewModel {
…
func openSettings() {
…
ExampleView().push(with: .verticalSlide)
…
}
…
}
There are two ways to do this:
pop
, pop(to type:)
, popToRoot
inside any view
struct ExampleView: NavigatableView {
…
func createButton() -> some View {
Button(action: popToRoot) { Text(“Tap to return to root”) }
}
…
}
NavigationManager
methods:
NavigationManager.pop()
NavigationManager.pop(to type:)
where type is the type of view you want to return toNavigationManager.popToRoot()
We’re almost done, but we’d like to describe three additional methods that you might like:
setAsNewRoot
method you can change the root of your navigation stack:
ExampleView()
.push(with: .verticalSlide)
.setAsNewRoot()
EnvironmentObject
can be passed, but remember to do this BEFORE pushing the view to the stack:
ExampleView()
.environmentObject(object)
.push(with: .verticalSlide)
onFocus
, not onAppear
onFocus
method:
struct ExampleView: NavigatableView {
var body: some View {
VStack(spacing: 0) {
Text(“Witaj okrutny świecie”)
Spacer()
Button(action: pop) { Text(“Pop”) }
}
.onFocus(self) {
// Do something
}
}
…
}
1. Taking Action When a Property Changes: Property Observers Swift lets you observe and respond to changes in a property’s ...
1. Creating Your Own Structs In Swift, a struct is a value type that you define with the struct keyword. ...
1. Trailing Closure Syntax When the last parameter to a function is a closure, you can write that closure after ...
1. What Is a Closure (and Why Swift Loves Them) A closure in Swift is a self-contained block of functionality ...
1. Providing Default Values for Function Parameters (Deep Dive) 1.1 Syntax and Ordering Declaration You assign a default right in ...