Skip to content

About

This project is created to demonstrate how to implement the Coordinator pattern in modern SwiftUI and pass data between its views.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

NavigationTests

Screenshot 2025-03-24 at 4 09 50 PM

A SwiftUI project demonstrating custom navigation handling using a Coordinator pattern with type-safe, hashable enum-based route management. This project explores how to push and pop views manually while passing data and completion handlers between screens.

📱 Overview

This app consists of three views:

  1. ContentView (FirstView) – Initial screen with a text field and button to navigate.
  2. SecondView – Displays the text entered in the first view and allows navigation to the third view.
  3. ThirdView – Accepts input and passes data back to the second view using a completion handler.

The project leverages a custom Coordinator class to handle navigation actions and view building, all driven by the ViewDestination enum.

🧩 Features

  • Custom Coordinator pattern with SwiftUI's NavigationStack
  • Type-safe enum-based routing (ViewDestination)
  • Navigation with associated data and completion closures
  • Reusable, environment-injected navigation logic
  • Clear navigation hierarchy: push, pop, popToRoot
  • Preview support for all views

🚀 Usage

Navigation Flow:

  1. Start in FirstView (ContentView):
    • Enter text → tap "Goto SecondView"
  2. SecondView:
    • Displays first view's text
    • Tap "Goto ThirdView" to input more text
  3. ThirdView:
    • Enter text → tap "Dismiss this view"
    • Text is passed back and displayed in SecondView

🧠 Key Concepts

  • Coordinator Class: Maintains a NavigationPath and handles pushing/popping views.
  • ViewDestination Enum: Defines all possible destinations with associated data.
  • @Environment(Coordinator.self): Views access coordinator for navigation actions.
  • @Observable (Coordinator): Keeps navigation path in sync.
  • Preview Support: All views use .environment(Coordinator()) for seamless previews.

About

This project is created to demonstrate how to implement the Coordinator pattern in modern SwiftUI and pass data between its views.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages