$ show SwiftfulThinking/SwiftfulRouting
SwiftfulRouting is a programmatic navigation library for SwiftUI that replaces native NavigationStack, sheets, fullScreenCovers, alerts, and confirmationDialogs with a unified, declarative router API. It provides a `RouterView` wrapper which injects an `AnyRouter` into the environment, enabling screens, alerts, modals, transitions (in-place content swaps), and modules (full hierarchy replacements) to be triggered from anywhere in the view tree. The library uses an internal `RouterViewModel` to manage a stack of `AnyDestinationStack` entries representing the screen hierarchy, with separate state for alerts, modals, and transitions. It also includes queue systems for screens and transitions, logging/analytics support, and resizable sheet configuration. The architecture is a Swift Package with one external dependency (SwiftfulRecursiveUI for LazyZStack), and targets iOS 16+, macOS 12+, tvOS 14+.
The LLM identified 2 files worth highlighting for reuse:
A class that wraps an array of `AnyDestination` and provides `setNewValueIfNeeded(newValue:animates:)` to update the array while applying an explicit animation transaction. This solves a subtle timing problem where SwiftUI's `onChange` handlers run outside the `withTransaction` context, causing animation flags to be lost. The class ensures that the navigation path updates with or without animation based on the original action's intent, making it a robust, reusable component for any SwiftUI NavigationStack path management.
A self-contained view modifier that adds an edge-swipe-back gesture overlay for custom transitions. It uses a drag gesture with configurable threshold and transition direction (trailing, leading, top, bottom) to detect a swipe-back intent and triggers a callback. The view offset is animated smoothly. This component is fully decoupled from the rest of the routing system and can be extracted as a standalone UIKit-style gesture wrapper for SwiftUI, useful for apps needing custom swipe-back behavior beyond the native NavigationStack.