Navigattie
  • December 4, 2023

Navigattie Logo

Navigation made simple

Implement navigation in your project in no time. Keep your code clean

Try demo we prepared

Navigattie is a free, and open-source library for SwiftUI that makes navigation easier and much cleaner.

  • Improves code quality. Push your view using the push(with:) method.
    Pop the selected one with pop(). Simple as never.
  • Designed for SwiftUI. While developing the library, we have used the power of SwiftUI to give you powerful tool to speed up your implementation process.

Getting Started


✋Requirements

Platforms Minimum Swift Version
iOS 15+ 5.0

⏳Installation

Swift package manager

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”))
]

Usage


1.  Setup library

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)
}
}

2. Declare structure of the view you want to push

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 {

}

3. Implement body method

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”) }
}
}

}

4. Implement configure(view: NavigationConfig) -> NavigationConfig method

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”) }
}
}

}

5. Present your view from any place you want!

Just call ExampleView().push(with:) from the selected place

struct SettingsViewModel {

func openSettings() {

ExampleView().push(with: .verticalSlide)

}

}

6. Closing views

There are two ways to do so:

  • By calling one of the methods poppop(to type:)popToRoot inside any view

struct ExampleView: NavigatableView {

func createButton() -> some View {
Button(action: popToRoot) { Text(“Tap to return to root”) }
}

}

  • By calling one of the static methods of NavigationManager:
    • NavigationManager.pop()
    • NavigationManager.pop(to type:) where type is the type of view you want to return to
    • NavigationManager.popToRoot()

GitHub


View Github

#iosswift #swift #swift5 #swiftlibrary #swiftnavigation #swiftpackage #swiftpackagemanager #swiftpackages #swiftui #swiftuicomponents #swiftuiframwork
YOU MIGHT ALSO LIKE...
EEStackLayout

A vertical stackview which takes subviews with different widths and adds them to it's rows with paddings, spacings etc.

AudioManager

AudioManager is a Swift package that provides a modular and easy-to-use interface for implementing audio feedback in your applications. It ...

CameraBackground

Features Both front and back camera supported. Flash modes: auto, on, off. Countdown timer. Tap to focus. Pinch to zoom. Usage  

DKCamera

Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so ...