Skip to content

Nillerr/NebulaNav

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nebula Navigation

This repository contains a proof-of-concept of rich routing in SwiftUI using Nillerr/Detour.

It is composed of Flows, Routes, Presentations and Flows as concepts of SwiftUI views, and assumes a rule of no more than one modal presentation at a time.

Presentations

Presentations presents Flows and Views presented as modals from a root view. Both sheet and fullScreenCover is supported, and changing the presented view between either of these awaits the dismissal of the other to provide seamless support.

import Detour

enum TodoPresentations {
  case edit
}

typealias TodoPresenter = Presenter<TodoPresentations>

struct ContentView: View {
  @StateObject var presenter = TodoPresenter()
  
  var body: some View {
    Presentations(presenter: presenter) {
      RootView(edit: { presenter.present(.edit) })
    } content: { presentation in
      switch presentation.presentable {
      case .edit:
        EditView(dismiss: { presenter.dismiss() })
      }
    }
  }
}

Routes

Routes navigates to Views through a NavigationView.

import Detour

enum TodoRoutes: Routeable {
  case todo(TodoDetailViewModel)

  var path: [TodoRoutes] {
    switch self {
    case .todo(let todo):
      return [.todo(todo)]
    }
  }
}

typealias TodoRouter = Router<TodoRoutes>

struct ContentView: View {
  @StateObject var router = TodoRouter()

  var body: some View {
    Routes(router: router) {
      TodoListView(selectTodo: { todo in router.navigate(to: .todo(todo)) })
    } content: { destination in
      switch destination {
      case .todo(let todo):
        TodoDetailView(viewModel: todo, dismiss: { router.navigate(to: nil) })
      }
    }
  }
}

Flows

Flows are navigation flows either using Routes or NavigationView itself.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages