This project demonstrates how to implement imperative navigation in SwiftUI using a coordinator pattern. This approach aims to separate the navigation logic from the view layer, making it easier to manage, maintain, and test complex navigation flows.
Medium Article: Link
- Decoupled Navigation Logic: Navigation logic is managed by a
Coordinator
, reducing the complexity of views. - Improved Testability: By extracting navigation logic into a separate component, you can write tests for navigation flows without involving the UI layer.
- Support for Modals: Handles both sheet and full-screen modals using a custom
ModalRoute
enum. - Clean and Maintainable Code: Uses SwiftUI's
NavigationStack
for a seamless and modern navigation experience.
- Coordinator Pattern: The
DefaultCoordinator
manages all navigation actions. It defines routes (viewB
,viewC
,viewD
) and maps them to the appropriate SwiftUI views. - Custom Navigation View: A custom
NavigationView
is used to integrate the coordinator with aNavigationStack
, allowing for imperative-style navigation. - Modals Management: Uses
ModalRoute
to manage presentation of views as sheets or full-screen covers.
To run this project:
-
Clone the repository:
git clone https://github.com/your-username/SwiftUI-Imperative-Navigation.git
-
Open the .xcodeproj file in Xcode.
-
Build and run the project on the simulator or your device.
Contributions are welcome! Feel free to open a pull request or submit issues for any bugs or suggestions.
This project is licensed under the MIT License.