$ show johnpatrickmorgan/TCACoordinators
TCACoordinators is a Swift library that brings the coordinator pattern to the Composable Architecture (TCA). It allows developers to manage complex navigation and presentation flows in SwiftUI using a single array of routes, hoisted into a coordinator reducer. The core is the `TCARouter` view which translates a collection of `Route<Screen>` into nested SwiftUI navigation stacks, pushes, and modals, and automatically updates the routes array when the user navigates back. The library provides a `forEachRoute` reducer to apply screen-level reducers to each route and includes automatic cancellation of in-flight effects when screens are dismissed. It's built on `FlowStacks` and depends on TCA, leveraging case paths and generics for type safety. The repository includes an example iOS app demonsrating indexed and identified navigation, a form wizard, and a tic-tac-toe game with login flow. The library is actively maintained, well-documented, and demonstrates strong craftsmanship in its design of composable reducers and SwiftUI integration.
The LLM identified 3 files worth highlighting for reuse:
Implements automatic cancellation of in-flight TCA effects when a screen (route) is removed from the coordinator's routes array. It wraps the coordinator reducer with a custom reducer that tags effects with a `CancellationIdentity` combining a coordinator ID and route ID. On dismiss, it cancels those tagged effects. This is a self-contained, generic pattern that can be extracted to other TCA projects needing per-screen effect lifecycle management, and demonsrates advanced use of reducers composability and generics.
Provides an extensive set of convenience methods on `IdentifiedArray` of routes for common navigation operations: `push`, `presentSheet`, `presentCover`, `goBack`, `goBackTo`, `goBackToRoot`, `pop`, `popTo`, `dismiss`, `dismissAll`, and case-path based `goBackTo`/`popTo`. These methods maintain safety with assertions and handle style-aware pop vs dismiss logic. The extension is fully generic over any route type adhering to `RouteProtocol` and is reusable in any project using `IdentifiedArray` and FlowStacks, demonsrating high-quality Swift extension design.
The core SwiftUI view that bridges TCA stores with FlowStacks navigation. It takes a store of `[Route<Screen>]` and a closure to create screen views. It observes the store and renders a `FlowStack` tree, pushing/presenting screens as the array changes. It handles both observed (`@Perception.Bindable`) and unobserved (old-style) stores via `UnobservedTCARouter`. This component is the main public API of the library, tightly integrated with TCA but could be extracted as a pattern for other navigation libraries.