- December 17, 2024
- Mins Read
Implement navigation in your project in no time. Keep your code clean
Navigattie is a free, and open-source library for SwiftUI that makes navigation easier and much cleaner.
push(with:)
method.pop()
. Simple as never.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 Navigattie as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: “https://github.com/Mijick/Navigattie”, branch(“main”))
]
Inside the @main
structure, call the implementNavigationView(config:)
method on the view that is to be the root view in your navigation structure. The view to be the root must be of type NavigatableView
. The method takes an optional argument – config
, that can be used to configure some modifiers for all navigation views in the application.
var body: some Scene {
WindowGroup {
ContentView()
.implementNavigationView(config: nil)
}
}
Navigattie provides the ability to push (or pop) any view using its built-in stack. In order to do so, it is necessary to confirm to NavigatableView
protocol. So that an example view you want to push will have the following declaration:
struct ExampleView: NavigatableView {
…
}
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”) }
}
}
…
}
This 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 customise it, regardless of the config we mentioned in step 1.
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
struct SettingsViewModel {
…
func openSettings() {
…
ExampleView().push(with: .verticalSlide)
…
}
…
}
There are two ways to do so:
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.pop()
NavigationManager.pop(to type:)
where type is the type of view you want to return toNavigationManager.popToRoot()
A vertical stackview which takes subviews with different widths and adds them to it's rows with paddings, spacings etc.
AudioManager is a Swift package that provides a modular and easy-to-use interface for implementing audio feedback in your applications. It ...