|
| 1 | + |
| 2 | + |
| 3 | +# 🚀 AwesomeNavigation |
| 4 | + |
| 5 | +**AwesomeNavigation** is a lightweight and elegant SwiftUI navigation library designed to make routing in iOS/macOS apps simple, declarative, and centralized — all while retaining native SwiftUI performance and flexibility. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## ✨ Features |
| 10 | + |
| 11 | +* 🚦 **Centralized Navigation Management** using a shared singleton or injectable instance. |
| 12 | +* 🛝 **Type-safe Route Definition** using the `ANRoute` protocol. |
| 13 | +* ↺ **Push**, **Pop**, **PushReplacement**, **PopToRoot** — all made easy. |
| 14 | +* 🔧 **Configurable Root and Transitions** via `ANConfig`. |
| 15 | +* 💡 **Declarative API** that fits naturally into SwiftUI’s ecosystem. |
| 16 | +* ⚡ **Swift Package** ready for seamless integration. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## 🎞 Installation |
| 21 | + |
| 22 | +Use **Swift Package Manager**: |
| 23 | + |
| 24 | +### In Xcode: |
| 25 | + |
| 26 | +1. Open your project. |
| 27 | +2. Go to **File > Add Packages…** |
| 28 | +3. Enter the repository URL: |
| 29 | + |
| 30 | + ``` |
| 31 | + https://github.com/k-arindam/AwesomeNavigation.git |
| 32 | + ``` |
| 33 | +4. Add the package and import it where needed: |
| 34 | + |
| 35 | + ```swift |
| 36 | + import AwesomeNavigation |
| 37 | + ``` |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## 🚀 Getting Started |
| 42 | + |
| 43 | +### Step 1: Define your routes |
| 44 | + |
| 45 | +```swift |
| 46 | +enum AppRoute: ANRoute { |
| 47 | + case home |
| 48 | + case settings |
| 49 | + case item(id: String) |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### Step 2: Initialize the app with a config |
| 54 | + |
| 55 | +```swift |
| 56 | +@main |
| 57 | +struct AwesomeNavigationExampleApp: App { |
| 58 | + var body: some Scene { |
| 59 | + WindowGroup { |
| 60 | + let config = ANConfig(initialRoute: AppRoute.home) { route in |
| 61 | + switch route { |
| 62 | + case .home: HomeView() |
| 63 | + case .settings: SettingsView() |
| 64 | + case .item(let id): ItemView(id: id) |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + ANApplication(with: config) |
| 69 | + .preferredColorScheme(.dark) |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## 🛍 Navigating Between Views |
| 78 | + |
| 79 | +You can use the provided navigation methods from any view using `@EnvironmentObject`. |
| 80 | + |
| 81 | +### Example: HomeView |
| 82 | + |
| 83 | +```swift |
| 84 | +struct HomeView: View { |
| 85 | + @EnvironmentObject var nav: AwesomeNavigation |
| 86 | + |
| 87 | + var body: some View { |
| 88 | + List { |
| 89 | + Section("PUSH") { |
| 90 | + Button("Push Settings View") { |
| 91 | + nav.push(AppRoute.settings) |
| 92 | + } |
| 93 | + |
| 94 | + Button("Push Item View") { |
| 95 | + nav.push(AppRoute.item(id: UUID().uuidString)) |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + Section("POP") { |
| 100 | + Button("Pop One View") { |
| 101 | + nav.pop() |
| 102 | + } |
| 103 | + |
| 104 | + Button("Pop to Root") { |
| 105 | + nav.popToRoot() |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + .navigationTitle("Home") |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 📌 Core Components |
| 117 | + |
| 118 | +### `AwesomeNavigation` |
| 119 | + |
| 120 | +A shared or injectable navigation controller that holds and manipulates the `NavigationPath`. |
| 121 | + |
| 122 | +### `ANRoute` |
| 123 | + |
| 124 | +Protocol to define your route types. Conforming types must be `Hashable`, `Codable`, and `Sendable`. |
| 125 | + |
| 126 | +### `ANConfig` |
| 127 | + |
| 128 | +Configuration for your application including: |
| 129 | + |
| 130 | +* Initial route |
| 131 | +* Animation style |
| 132 | +* Route-to-View builder closure |
| 133 | + |
| 134 | +### `ANApplication` |
| 135 | + |
| 136 | +Entry-point `View` that wraps `NavigationStack` and injects navigation environment. |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +## 📈 Future Scope |
| 141 | + |
| 142 | +Here are a few exciting features planned for upcoming releases: |
| 143 | + |
| 144 | +* [ ] 🥪 Unit-testable navigation by allowing injection of `AwesomeNavigation` (non-singleton mode) |
| 145 | +* [ ] 🔍 Deep linking support via pre-filled `NavigationPath` |
| 146 | +* [ ] 🧱 Scoped navigation contexts (multiple stacks in one app) |
| 147 | +* [ ] 🛡️ Interception hooks (e.g., `onRouteWillPush`, auth guards, analytics) |
| 148 | +* [ ] 🧑💻 DevTools-style route inspector/debug overlay |
| 149 | +* [ ] 📱 iPad/macOS optimized UI state sync (split views, multiple windows) |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## 🛠 Contributing |
| 154 | + |
| 155 | +Pull requests are welcome! Feel free to open issues for bug reports or feature suggestions. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 📄 Legal |
| 160 | + |
| 161 | +- [**MIT License**](LICENSE) |
| 162 | +- [**Code of Conduct**](CODE_OF_CONDUCT.md) |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## 🙌 Acknowledgements |
| 167 | + |
| 168 | +Inspired by: |
| 169 | + |
| 170 | +* SwiftUI's native navigation stack |
| 171 | +* Navigator paradigms from Flutter and React Router |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## ❤️ Example App |
| 176 | + |
| 177 | +A demo implementation is included in the `Example/` folder. |
| 178 | + |
| 179 | +```swift |
| 180 | +@main |
| 181 | +struct AwesomeNavigationExampleApp: App { |
| 182 | + ... |
| 183 | +} |
| 184 | +``` |
0 commit comments