Skip to content

SwiftUI and UIKit navigations and interoperability made simple (again) and testable.

License

Notifications You must be signed in to change notification settings

JuanColilla/Sailor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sailor: Navigation for SwiftUI the original way.

Swift 5.7

Sailor is a navigation library for Swift, designed to simplify the management of view transitions in SwiftUI and UIKit applications. Sailor provides an easy-to-use Navigator protocol, a default implementation (DefaultNavigator), and a NavigationLogger for testing and logging navigation actions (if desired and implemented).

Features

  • Simple navigation handling for both SwiftUI and UIKit
  • Customizable with Navigator protocol and Navegatable protocol
  • Navigation logging for easy debugging and testing (not by default).

Usage

1. Create a Screen enum

Implement the Navegatable protocol in an enum where you define all your app's destination screens:

import Sailor

enum Screen: Navegatable {
    case login(params: LoginParams)

    var view: AnyView {
        switch self {
        case .login(let params):
            return Screen.loginView(params: params)
        }
    }
}

2. Extend Screen for each SwiftUI View

For every SwiftUI View that represents a screen in your app, create an extension of Screen. This example is for a LoginView:

extension Screen {
    static func loginView(params: LoginParams) -> AnyView {
        return LoginView(params: params)
            .eraseToAnyView()
    }
}

3. Use DefaultNavigator or create a custom Navigator

Instantiate the DefaultNavigator with the initial root screen or create a custom Navigator by implementing the Navigator protocol (using an environment class as a singleton is recommended here to avoid passing the Navigator and to have access across the Module):

let navigator = DefaultNavigator(rootScreen: .login(params: LoginParams()))

navigator.push(to: .login(params: LoginParams()))
navigator.present(modal: .login(params: LoginParams()))

Installation

Swift Package Manager

Add Sailor as a dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/JuanColilla/Sailor.git", from: "1.0.0")
]

License

Sailor is available under the MIT license. See the LICENSE file for more information.

About

SwiftUI and UIKit navigations and interoperability made simple (again) and testable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages