{"id":47250224,"url":"https://github.com/Sedlacek-Solutions/SwiftUI-Navigation","last_synced_at":"2026-03-28T18:01:11.105Z","repository":{"id":212741385,"uuid":"732202613","full_name":"Sedlacek-Solutions/SwiftUI-Navigation","owner":"Sedlacek-Solutions","description":"SwiftUI library for abstracting navigation logic from views","archived":false,"fork":false,"pushed_at":"2025-11-12T02:51:00.000Z","size":2472,"stargazers_count":477,"open_issues_count":0,"forks_count":29,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-01-25T22:38:28.422Z","etag":null,"topics":["abstraction","navigation","navigationdestination","navigationlink","navigationstack","routing","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sedlacek-Solutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-15T22:59:52.000Z","updated_at":"2026-01-16T02:16:52.000Z","dependencies_parsed_at":"2024-02-11T03:19:42.941Z","dependency_job_id":"4921f77f-5709-42cd-94b6-235b783ffa69","html_url":"https://github.com/Sedlacek-Solutions/SwiftUI-Navigation","commit_stats":{"total_commits":63,"total_committers":5,"mean_commits":12.6,"dds":0.4444444444444444,"last_synced_commit":"b996580a66fc66f9ea01222b18a281f157001161"},"previous_names":["jamessedlacek/routing","sedlacek-solutions/swiftui-navigation"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Sedlacek-Solutions/SwiftUI-Navigation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sedlacek-Solutions%2FSwiftUI-Navigation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sedlacek-Solutions%2FSwiftUI-Navigation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sedlacek-Solutions%2FSwiftUI-Navigation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sedlacek-Solutions%2FSwiftUI-Navigation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sedlacek-Solutions","download_url":"https://codeload.github.com/Sedlacek-Solutions/SwiftUI-Navigation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sedlacek-Solutions%2FSwiftUI-Navigation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31116087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-28T17:50:59.904Z","status":"ssl_error","status_checked_at":"2026-03-28T17:50:59.435Z","response_time":79,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstraction","navigation","navigationdestination","navigationlink","navigationstack","routing","swiftui"],"created_at":"2026-03-14T13:00:25.253Z","updated_at":"2026-03-28T18:01:11.097Z","avatar_url":"https://github.com/Sedlacek-Solutions.png","language":"Swift","readme":"# SwiftUI-Navigation\n\n[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![GitHub stars](https://img.shields.io/github/stars/Sedlacek-Solutions/SwiftUI-Navigation.svg)](https://github.com/Sedlacek-Solutions/SwiftUI-Navigation/stargazers)\n[![GitHub forks](https://img.shields.io/github/forks/Sedlacek-Solutions/SwiftUI-Navigation.svg?color=blue)](https://github.com/Sedlacek-Solutions/SwiftUI-Navigation/network)\n[![GitHub contributors](https://img.shields.io/github/contributors/Sedlacek-Solutions/SwiftUI-Navigation.svg?color=blue)](https://github.com/Sedlacek-Solutions/SwiftUI-Navigation/network)\n\u003ca href=\"https://github.com/Sedlacek-Solutions/SwiftUI-Navigation/pulls\"\u003e\u003cimg src=\"https://img.shields.io/github/issues-pr/Sedlacek-Solutions/SwiftUI-Navigation\" alt=\"Pull Requests Badge\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Sedlacek-Solutions/SwiftUI-Navigation/issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/Sedlacek-Solutions/SwiftUI-Navigation\" alt=\"Issues Badge\"/\u003e\u003c/a\u003e\n\n## Description\n\n`SwiftUI-Navigation` is a **lightweight** SwiftUI navigation library.\n- Leverages 1st-party APIs `NavigationStack` \u0026 `NavigationDestination`.\n- Never be confused about `NavigationLink` or `NavigationPath` again! (You don't need them)\n- Type-Safe Navigation (better performance than type-erasing).\n- Centralized Navigation Logic.\n- Dynamic Navigation Stack Management.\n- Unit Tested protocol implementations.\n- Zero 3rd party dependencies.\n\n\u003cbr\u003e\n\n## Table of Contents\n1. [Requirements](#requirements)\n2. [Installation](#installation)\n3. [Getting Started](#getting-started)\n4. [Passing Data Example](#passing-data-example)\n5. [View Extensions](#view-extensions)\n6. [Under the hood](#under-the-hood)\n\n\u003cbr\u003e\n\n## Requirements\n\n| Platform | Minimum Version |\n|----------|-----------------|\n| iOS      | 16.0            |\n| macOS    | 13.0            |\n| tvOS     | 16.0            |\n| watchOS  | 9.0             |\n\n\u003cbr\u003e\n\n## Installation\n\nYou can install `SwiftUI-Navigation` using the Swift Package Manager.\n\n1. In Xcode, select `File` \u003e `Add Package Dependencies`.\n\u003cbr\u003e\n\n2. Copy \u0026 paste the following into the `Search or Enter Package URL` search bar.\n```\nhttps://github.com/Sedlacek-Solutions/SwiftUI-Navigation.git\n```\n\u003cbr\u003e\n\n3. Xcode will fetch the repository \u0026 the `SwiftUI-Navigation` library will be added to your project.\n\n\u003cbr\u003e\n\n## Getting Started\n\n1. Create a `Destination` enum that conforms to the `Destination` protocol.\n\n``` swift\nimport Navigation\nimport SwiftUI\n\nenum ExampleDestination: Destination {\n    case detail\n    case settings\n    \n    var body: some View {\n        switch self {\n        case .detail:\n            DetailView()\n        case .settings:\n            SettingsView()\n        }\n    }\n}\n```\n\n2. Create a `DestinationState` object and wrap your `RootView` with a `Navigator`.\n\n``` swift\nimport SwiftUI\nimport Navigation\n\nstruct ContentView: View {\n    @DestinationState private var destinations: [ExampleDestination] = []\n\n    var body: some View {\n        Navigator(path: $destinations) {\n            Button(\"Go to Settings\") {\n                destinations.navigate(to: .settings)\n            }\n        }\n    }\n}\n```\n\n3. Handle navigation using the `DestinationState` functions\n\n```swift\n/// Navigate back in the stack by a specified count.\nfunc navigateBack(_ count: Int)\n\n/// Navigate back to a specific destination in the stack.\nfunc navigateBack(to destination: Destination)\n\n/// Navigate to the root of the stack by emptying it.\nfunc navigateToRoot()\n\n/// Navigate to a specific destination by appending it to the stack.\nfunc navigate(to destination: Destination)\n\n/// Navigate to multiple destinations by appending them to the stack.\nfunc navigate(to destinations: [Destination])\n\n/// Replace the current stack with new destinations.\nfunc replace(with destinations: [Destination])\n```\n\n\u003cbr\u003e\n\n## Passing Data Example\n\n```swift\nimport Navigation\nimport SwiftUI\n\nenum ContentDestination: Destination {\n    case detail(Color)\n    case settings\n\n    var body: some View {\n        switch self {\n        case .detail(let color):\n            ColorDetail(color: color)\n        case .settings:\n            SettingsView()\n        }\n    }\n}\n\nstruct ContentView: View {\n    @DestinationState private var destinations: [ContentDestination] = []\n    private let colors: [Color] = [.red, .green, .blue]\n\n    var body: some View {\n        Navigator(path: $destinations) {\n            List(colors, id: \\.self) { color in\n                color\n                    .onTapGesture {\n                        destinations.navigate(to: .detail(color))\n                    }\n            }\n        }\n    }\n}\n\nstruct ColorDetail: View {\n    private let color: Color\n\n    init(color: Color) {\n        self.color = color\n    }\n\n    var body: some View {\n        color.frame(maxWidth: .infinity, maxHeight: .infinity)\n    }\n}\n```\n\n\u003cbr\u003e\n\n## View Extensions\n\n`SwiftUI-Navigation` provides several `View` extensions to simplify common navigation and presentation patterns when working with `Destination` types.\n\n### `navigationDestination(for: DestinationType.self)`\n\nThis extension is a convenience wrapper around the standard SwiftUI `navigationDestination(for:destination:)` modifier. It's tailored for use with types conforming to `Destination`, automatically using the `Destination` instance itself as the destination view.\n\n```swift\n// Usage within a view:\n// SomeView().navigationDestination(for: MyDestination.self)\n// This is often handled automatically by Navigator.\n```\n`Navigator` uses this extension internally to set up navigation for your `Destination` enum.\n\n### `sheet(item:onDismiss:)`\n\nPresents a sheet when a binding to an optional `Destination \u0026 Identifiable` item becomes non-nil. The content of the sheet is the `Destination` item itself.\n\n-   `item`: A `Binding` to an optional `Destination \u0026 Identifiable` item.\n-   `onDismiss`: An optional closure executed when the sheet dismisses.\n\n**Note:** The `Destination` type used with this modifier must also conform to `Identifiable`.\n```swift\nimport SwiftUI\nimport Navigation\n\n// Ensure your Destination enum conforms to Identifiable.\n// For enums with associated values, you might need to add an explicit `id`.\nenum ModalDestination: Destination, Identifiable {\n    case helpPage\n    case userDetails(id: String)\n\n    // Example of making it Identifiable\n    var id: String {\n        switch self {\n        case .helpPage:\n            return \"helpPage\"\n        case .userDetails(let id):\n            return \"userDetails-\\(id)\"\n        }\n    }\n\n    var body: some View {\n        switch self {\n        case .helpPage:\n            HelpView() // Placeholder\n        case .userDetails(let id):\n            UserDetailsView(userID: id) // Placeholder\n        }\n    }\n}\n\nstruct MyContentView: View {\n    @State private var sheetItem: ModalDestination?\n\n    var body: some View {\n        Button(\"Show Help Sheet\") {\n            sheetItem = .helpPage\n        }\n        .sheet(item: $sheetItem)\n    }\n}\n\n// Placeholder Views for example\nstruct HelpView: View { var body: some View { Text(\"Help Information\") } }\nstruct UserDetailsView: View {\n    let userID: String\n    var body: some View { Text(\"Details for user \\(userID)\") }\n}\n```\n\n### `navigationDestination(item:)` (iOS 17.0+)\n\nAvailable on iOS 17.0+, macOS 14.0+, tvOS 17.0+, watchOS 10.0+.\n\nPresents a view using `navigationDestination(item:destination:)` when a binding to an optional `Destination` item becomes non-nil. The destination view is the `Destination` item itself. This is useful for modal-style presentations or alternative navigation flows that don't necessarily push onto the main `NavigationStack`.\n\n-   `item`: A `Binding` to an optional `Destination` item.\n```swift\nimport SwiftUI\nimport Navigation\n\n// Assuming MyDetailDestination is a Destination enum\n// enum MyDetailDestination: Destination { case info, settings ... }\n\n@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)\nstruct AnotherScreen: View {\n    @State private var presentedDetail: MyDetailDestination? // MyDetailDestination conforms to Destination\n\n    var body: some View {\n        Button(\"Show Info Modally\") {\n            presentedDetail = .info // Assuming .info is a case in MyDetailDestination\n        }\n        .navigationDestination(item: $presentedDetail)\n    }\n}\n```\n\n\u003cbr\u003e\n\n## Under the hood\n\nThe `Navigator` essentially wraps your view with a `NavigationStack`. It uses the `navigationDestination(for: DestinationType.self)` view extension (detailed in the \"View Extensions\" section) to automatically handle presenting the views associated with your `Destination` types.\n```swift\n// Simplified structure of Navigator's body:\nNavigationStack(path: $path) { // $path is your @DestinationState's binding\n    rootContent()\n        .navigationDestination(for: DestinationType.self) // Uses the Destination-specific extension\n}\n```\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSedlacek-Solutions%2FSwiftUI-Navigation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSedlacek-Solutions%2FSwiftUI-Navigation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSedlacek-Solutions%2FSwiftUI-Navigation/lists"}