From 03a3fb609678e2496fb2e84beedf6cf7e6ec7afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A0i=20L=C3=AA?= Date: Fri, 15 Mar 2024 15:37:58 +0700 Subject: [PATCH 01/22] Create FUNDING.yml (#12) --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..8116b40 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +buy_me_a_coffee: iletai +custom: ["https://www.paypal.me/iletai"] From c7e88426acf2adb38d1beb1c6f3bdc111cfcf770 Mon Sep 17 00:00:00 2001 From: iletai Date: Mon, 19 Oct 2026 23:13:12 +0700 Subject: [PATCH 02/22] build: upgrade package manifest to swift 6.0 and macos 14 --- Package.swift | 19 +++++++++++-------- .../BaseNavigationStack.swift | 2 +- .../Utils/Collection+Extension.swift | 9 ++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Package.swift b/Package.swift index 92da97d..25f7a6b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,21 +6,24 @@ import PackageDescription let package = Package( name: "BaseNavigationStack", platforms: [ - .macOS(.v13), .iOS(.v17) + .macOS(.v14), .iOS(.v17) ], products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "BaseNavigationStack", - targets: ["BaseNavigationStack"]), + targets: ["BaseNavigationStack"] + ), ], targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. .target( - name: "BaseNavigationStack"), + name: "BaseNavigationStack", + swiftSettings: [ + .enableUpcomingFeature("StrictConcurrency") + ] + ), .testTarget( name: "BaseNavigationStackTests", - dependencies: ["BaseNavigationStack"]), + dependencies: ["BaseNavigationStack"] + ), ] ) diff --git a/Sources/BaseNavigationStack/BaseNavigationStack.swift b/Sources/BaseNavigationStack/BaseNavigationStack.swift index 9ccab66..85045b2 100644 --- a/Sources/BaseNavigationStack/BaseNavigationStack.swift +++ b/Sources/BaseNavigationStack/BaseNavigationStack.swift @@ -44,7 +44,7 @@ public extension BaseNavigationStack { state.presentingFullScreen = nil state.presentingSheet = nil } - state.navigationPath.removeAllSafe() + state.navigationPath.removeAll() } /// Change Base Navigation Stack diff --git a/Sources/BaseNavigationStack/Utils/Collection+Extension.swift b/Sources/BaseNavigationStack/Utils/Collection+Extension.swift index e9c04fc..858df56 100644 --- a/Sources/BaseNavigationStack/Utils/Collection+Extension.swift +++ b/Sources/BaseNavigationStack/Utils/Collection+Extension.swift @@ -8,19 +8,14 @@ import Foundation extension Collection { - subscript (safe index: Index) -> Element? { + public subscript (safe index: Index) -> Element? { indices.contains(index) ? self[index] : nil } } extension Array { - mutating func removeLastSafe() { + public mutating func removeLastSafe() { guard !isEmpty else { return } removeLast() } - - mutating func removeAllSafe() { - guard !isEmpty else { return } - removeAll() - } } From cf3ba4f402d0ffe07187c7c64052c286956ec813 Mon Sep 17 00:00:00 2001 From: iletai Date: Mon, 19 Oct 2026 23:14:50 +0700 Subject: [PATCH 03/22] feat(core): implement NavigationRouter 2.0 with swift 6 strict concurrency --- .../BaseNavigationStack.swift | 45 +++---- .../Interface/BaseViewProtocol.swift | 3 +- .../NavigationRouter.swift | 90 ++++++++++++++ .../BaseNavigationStackV1Tests.swift | 42 +++++++ .../NavigationRouterTests.swift | 116 ++++++++++++++++++ 5 files changed, 273 insertions(+), 23 deletions(-) create mode 100644 Sources/BaseNavigationStack/NavigationRouter.swift create mode 100644 Tests/BaseNavigationStackTests/BaseNavigationStackV1Tests.swift create mode 100644 Tests/BaseNavigationStackTests/NavigationRouterTests.swift diff --git a/Sources/BaseNavigationStack/BaseNavigationStack.swift b/Sources/BaseNavigationStack/BaseNavigationStack.swift index 85045b2..77c4590 100644 --- a/Sources/BaseNavigationStack/BaseNavigationStack.swift +++ b/Sources/BaseNavigationStack/BaseNavigationStack.swift @@ -5,13 +5,14 @@ import SwiftUI import Foundation import Observation +@MainActor @Observable /// Base Navigation Stack With Generic Type. -public class BaseNavigationStack where ScreenView: BaseViewProtocol { +public final class BaseNavigationStack: @unchecked Sendable where ScreenView: BaseViewProtocol { private(set) var state: RootingState - public var urlHandler: ((URL) -> OpenURLAction.Result)? + public var urlHandler: (@MainActor (URL) -> OpenURLAction.Result)? - public init(isPresented: Binding) { + public init(isPresented: Binding = .constant(nil)) { state = RootingState( isPresented: isPresented ) @@ -21,47 +22,47 @@ public class BaseNavigationStack where ScreenView: BaseViewProtocol public extension BaseNavigationStack { /// According navigation full screen flow of Apple /// https://developer.apple.com/design/human-interface-guidelines/going-full-screen - /// We Will Only Support Case Full Screen To Target Last View Embed In Navigation Stack - /// So If View Is Presenting SomeView. Must Dismiss. If Want To Navigation To Another View But Also Keep Current. - /// Please Embed Target View In Owner Navigation Stack Different /// Navigation Stack Push To View /// - Parameter viewSpec: Push View @MainActor func pushToView(_ viewSpec: ScreenView) { - state.navigationPath.append(viewSpec) + // Debounce: prevent duplicate immediate pushes of the exact same target + if state.navigationPath.last != viewSpec { + state.navigationPath.append(viewSpec) + } } - + /// Pop To Back Previous View In Navigation Stack @MainActor func popBack() { state.navigationPath.removeLastSafe() } - + /// Pop To Root View Init In Navigation Stack @MainActor func navigateToRoot() { - if state.isPresenting { - state.presentingFullScreen = nil - state.presentingSheet = nil - } + state.presentingFullScreen = nil + state.presentingSheet = nil state.navigationPath.removeAll() } - + /// Change Base Navigation Stack /// - Parameter path: Replace With Another Navigation Path @MainActor func replaceNavigationStack(path: [ScreenView]) { + state.presentingFullScreen = nil + state.presentingSheet = nil state.navigationPath = path } - /// Present Sheet With Define Type View + /// Present Sheet With Define Type View /// - Parameter viewSpec: present Sheet View @MainActor func presentSheet(_ viewSpec: ScreenView) { state.presentingSheet = viewSpec } - /// Full Screen View In Bas Navigation Stack + /// Full Screen View In Base Navigation Stack /// - Parameter viewSpec: PushViewTarget @MainActor func presentFullScreen(_ viewSpec: ScreenView) { @@ -75,15 +76,15 @@ public extension BaseNavigationStack { state.presentingSheet = nil } else if state.presentingFullScreen != nil { state.presentingFullScreen = nil - } else if navigationPath.count > 1 { + } else if !state.navigationPath.isEmpty { state.navigationPath.removeLast() } else { state.isPresented.wrappedValue = nil } } - public func handleOpenURL(url: URL) -> OpenURLAction.Result { - // TODO: Update URL Handler + @MainActor + func handleOpenURL(url: URL) -> OpenURLAction.Result { return urlHandler?(url) ?? .systemAction } } @@ -92,15 +93,15 @@ public extension BaseNavigationStack { var navigationPath: Binding<[ScreenView]> { binding(keyPath: \.navigationPath) } - + var presentingSheet: Binding { binding(keyPath: \.presentingSheet) } - + var presentingFullScreen: Binding { binding(keyPath: \.presentingFullScreen) } - + var isPresented: Binding { state.isPresented } diff --git a/Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift b/Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift index 0108118..514a088 100644 --- a/Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift +++ b/Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift @@ -8,7 +8,7 @@ import Foundation import SwiftUI -public protocol BaseViewProtocol: Identifiable, Hashable { +public protocol BaseViewProtocol: Identifiable, Hashable, Sendable { associatedtype PresentSheetScreenView: View associatedtype DestinationView: View associatedtype PresentFullScreenView: View @@ -17,6 +17,7 @@ public protocol BaseViewProtocol: Identifiable, Hashable { @ViewBuilder func withSheetDestination() -> PresentSheetScreenView + @MainActor @ViewBuilder func withFullScreenDestination() -> PresentFullScreenView diff --git a/Sources/BaseNavigationStack/NavigationRouter.swift b/Sources/BaseNavigationStack/NavigationRouter.swift new file mode 100644 index 0000000..1e5ce50 --- /dev/null +++ b/Sources/BaseNavigationStack/NavigationRouter.swift @@ -0,0 +1,90 @@ +// +// NavigationRouter.swift +// BaseNavigationStack +// +// Created by Claude on 19/10/2026. +// + +import SwiftUI +import Observation + +/// Modern 2.0 Router for SwiftUI Data-Driven Navigation. +/// Unifies Stack navigation, Sheet presentation, and FullScreenCover in a single point of truth. +@MainActor +@Observable +public final class NavigationRouter: @unchecked Sendable { + public var path: [Route] = [] + public var sheet: Sheet? + public var cover: Cover? + + public init( + initialPath: [Route] = [], + initialSheet: Sheet? = nil, + initialCover: Cover? = nil + ) { + self.path = initialPath + self.sheet = initialSheet + self.cover = initialCover + } + + /// Pushes a new route onto the navigation stack. + /// Deduplicates immediate subsequent pushes of the identical route to prevent UI glitches. + public func push(_ route: Route) { + if path.last != route { + path.append(route) + } + } + + /// Pops the topmost screen from the navigation stack. + public func pop() { + _ = path.popLast() + } + + /// Pops back `count` screens from the stack safely. + public func pop(count: Int) { + let itemsToRemove = min(count, path.count) + guard itemsToRemove > 0 else { return } + path.removeLast(itemsToRemove) + } + + /// Pops back to the root screen of the navigation stack. + public func popToRoot() { + sheet = nil + cover = nil + path.removeAll() + } + + /// Replaces the entire stack with a new path, clearing any active sheets/covers. + public func replacePath(_ newPath: [Route]) { + sheet = nil + cover = nil + path = newPath + } + + /// Presents a modal sheet. + public func present(sheet: Sheet) { + self.sheet = sheet + } + + /// Presents a full screen cover. + public func present(cover: Cover) { + self.cover = cover + } + + /// Dismisses active sheet/cover if any, otherwise pops top screen from navigation stack. + public func dismiss() { + if sheet != nil { + sheet = nil + } else if cover != nil { + cover = nil + } else { + _ = path.popLast() + } + } + + /// Clears all modals without altering the underlying navigation stack. + public func dismissModals() { + sheet = nil + cover = nil + } +} diff --git a/Tests/BaseNavigationStackTests/BaseNavigationStackV1Tests.swift b/Tests/BaseNavigationStackTests/BaseNavigationStackV1Tests.swift new file mode 100644 index 0000000..330a9ca --- /dev/null +++ b/Tests/BaseNavigationStackTests/BaseNavigationStackV1Tests.swift @@ -0,0 +1,42 @@ +import XCTest +import SwiftUI +@testable import BaseNavigationStack + +enum LegacyTarget: BaseViewProtocol { + case first + case second + var id: String { "\(self)" } + + @MainActor + func withSheetDestination() -> some View { EmptyView() } + @MainActor + func withFullScreenDestination() -> some View { EmptyView() } + @MainActor + func withNavigationDestination() -> some View { EmptyView() } +} + +@MainActor +final class BaseNavigationStackV1Tests: XCTestCase { + func testLegacyDismissOnSingleScreen() { + let stack = BaseNavigationStack(isPresented: .constant(nil)) + stack.pushToView(.first) + XCTAssertEqual(stack.navigationPath.wrappedValue.count, 1) + + // Verifying fix: previously required count > 1 to pop, now pops when count == 1 + stack.dismiss() + XCTAssertEqual(stack.navigationPath.wrappedValue.count, 0) + } + + func testLegacyReplaceClearsModals() { + let stack = BaseNavigationStack(isPresented: .constant(nil)) + stack.presentSheet(.first) + stack.presentFullScreen(.first) + XCTAssertNotNil(stack.presentingSheet.wrappedValue) + XCTAssertNotNil(stack.presentingFullScreen.wrappedValue) + + stack.replaceNavigationStack(path: [.second]) + XCTAssertNil(stack.presentingSheet.wrappedValue) + XCTAssertNil(stack.presentingFullScreen.wrappedValue) + XCTAssertEqual(stack.navigationPath.wrappedValue, [.second]) + } +} diff --git a/Tests/BaseNavigationStackTests/NavigationRouterTests.swift b/Tests/BaseNavigationStackTests/NavigationRouterTests.swift new file mode 100644 index 0000000..efe8390 --- /dev/null +++ b/Tests/BaseNavigationStackTests/NavigationRouterTests.swift @@ -0,0 +1,116 @@ +import XCTest +import SwiftUI +@testable import BaseNavigationStack + +enum TestRoute: Hashable, Sendable { + case home + case detail(id: Int) + case profile +} + +struct TestSheet: Identifiable, Hashable, Sendable { + let id: String +} + +struct TestCover: Identifiable, Hashable, Sendable { + let id: String +} + +@MainActor +final class NavigationRouterTests: XCTestCase { + + func testPushAndPop() { + let router = NavigationRouter() + XCTAssertTrue(router.path.isEmpty) + + router.push(.detail(id: 1)) + XCTAssertEqual(router.path, [.detail(id: 1)]) + + router.push(.profile) + XCTAssertEqual(router.path.count, 2) + + router.pop() + XCTAssertEqual(router.path, [.detail(id: 1)]) + + router.pop() + XCTAssertTrue(router.path.isEmpty) + + // Pop on empty should be safe + router.pop() + XCTAssertTrue(router.path.isEmpty) + } + + func testPopMultiple() { + let router = NavigationRouter() + router.push(.home) + router.push(.detail(id: 1)) + router.push(.detail(id: 2)) + router.push(.profile) + XCTAssertEqual(router.path.count, 4) + + router.pop(count: 2) + XCTAssertEqual(router.path, [.home, .detail(id: 1)]) + + // Popping more than available should empty the stack safely + router.pop(count: 10) + XCTAssertTrue(router.path.isEmpty) + } + + func testDuplicatePushDebounce() { + let router = NavigationRouter() + router.push(.home) + router.push(.home) // Repeated immediate push + XCTAssertEqual(router.path.count, 1) + + router.push(.detail(id: 1)) + XCTAssertEqual(router.path.count, 2) + } + + func testDismissLadder() { + let router = NavigationRouter() + router.push(.home) + + // Case 1: Stack only with 1 item - dismiss should pop it (v1 bug was: count > 1 required) + router.dismiss() + XCTAssertTrue(router.path.isEmpty, "Dismiss should pop the single item in stack") + + // Case 2: Sheet active - dismiss should close sheet and keep stack intact + router.push(.home) + router.present(sheet: TestSheet(id: "s1")) + XCTAssertNotNil(router.sheet) + router.dismiss() + XCTAssertNil(router.sheet) + XCTAssertEqual(router.path, [.home]) + + // Case 3: Cover active - dismiss should close cover and keep stack intact + router.present(cover: TestCover(id: "c1")) + XCTAssertNotNil(router.cover) + router.dismiss() + XCTAssertNil(router.cover) + XCTAssertEqual(router.path, [.home]) + } + + func testReplacePathClearsModals() { + let router = NavigationRouter() + router.push(.home) + router.present(sheet: TestSheet(id: "s1")) + router.present(cover: TestCover(id: "c1")) + + router.replacePath([.detail(id: 99)]) + XCTAssertNil(router.sheet) + XCTAssertNil(router.cover) + XCTAssertEqual(router.path, [.detail(id: 99)]) + } + + func testPopToRootClearsAll() { + let router = NavigationRouter() + router.push(.home) + router.push(.detail(id: 1)) + router.present(sheet: TestSheet(id: "s1")) + + router.popToRoot() + XCTAssertTrue(router.path.isEmpty) + XCTAssertNil(router.sheet) + XCTAssertNil(router.cover) + } +} From 346ca1392df2afa30cf49b2832a6c14ec91d2dad Mon Sep 17 00:00:00 2001 From: iletai Date: Mon, 19 Oct 2026 23:15:24 +0700 Subject: [PATCH 04/22] test: add nested navigation and concurrency safety test suites --- .../ConcurrencySafetyTests.swift | 47 ++++++++++ .../NestedNavigationTests.swift | 87 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 Tests/BaseNavigationStackTests/ConcurrencySafetyTests.swift create mode 100644 Tests/BaseNavigationStackTests/NestedNavigationTests.swift diff --git a/Tests/BaseNavigationStackTests/ConcurrencySafetyTests.swift b/Tests/BaseNavigationStackTests/ConcurrencySafetyTests.swift new file mode 100644 index 0000000..ab4c350 --- /dev/null +++ b/Tests/BaseNavigationStackTests/ConcurrencySafetyTests.swift @@ -0,0 +1,47 @@ +import XCTest +import SwiftUI +@testable import BaseNavigationStack + +enum HeavyRoute: Hashable, Sendable { + case item(Int) +} + +struct EmptySheet: Identifiable, Hashable, Sendable { + let id: String +} + +@MainActor +final class ConcurrencySafetyTests: XCTestCase { + + /// Scenario: User taps a button multiple times rapidly in the same frame/runloop. + /// Deduplication prevents pushing duplicate consecutive screens. + func testRapidTapDebounce() { + let router = NavigationRouter() + + // 10 rapid taps on the same item + for _ in 0..<10 { + router.push(.item(42)) + } + + XCTAssertEqual(router.path.count, 1, "Immediate consecutive identical pushes must be debounced to 1") + XCTAssertEqual(router.path, [.item(42)]) + + // Tapping a different item immediately goes through + router.push(.item(43)) + XCTAssertEqual(router.path.count, 2) + } + + /// Scenario: Calling pop or dismiss on an empty router should be a graceful no-op. + func testSafeDismissOnEmptyStack() { + let router = NavigationRouter() + + XCTAssertTrue(router.path.isEmpty) + router.pop() + router.pop(count: 5) + router.dismiss() + router.dismissModals() + router.popToRoot() + + XCTAssertTrue(router.path.isEmpty) + } +} diff --git a/Tests/BaseNavigationStackTests/NestedNavigationTests.swift b/Tests/BaseNavigationStackTests/NestedNavigationTests.swift new file mode 100644 index 0000000..b635210 --- /dev/null +++ b/Tests/BaseNavigationStackTests/NestedNavigationTests.swift @@ -0,0 +1,87 @@ +import XCTest +import SwiftUI +@testable import BaseNavigationStack + +// MARK: - Route Definitions for Multi-Level Nested Flow + +enum AppTabRoute: Hashable, Sendable { + case feed + case settings +} + +enum SettingsSubRoute: Hashable, Sendable { + case general + case security + case advancedOptions +} + +struct SettingsModal: Identifiable, Hashable, Sendable { + let id: String +} + +struct EmptyCover: Identifiable, Hashable, Sendable { + let id: String +} + +@MainActor +final class NestedNavigationTests: XCTestCase { + + /// Scenario: A screen in the main stack opens a Modal Sheet. + /// The Modal Sheet contains its OWN child NavigationRouter with independent stack. + /// Child stack navigates 2 levels deep, then dismisses back to modal root, + /// then parent dismisses the entire modal cleanly. + func testParentChildRouterLifecycle() { + // 1. Parent Root Router + let parentRouter = NavigationRouter() + parentRouter.push(.feed) + XCTAssertEqual(parentRouter.path, [.feed]) + + // 2. Parent presents Settings modal + parentRouter.present(sheet: SettingsModal(id: "settings-sheet")) + XCTAssertNotNil(parentRouter.sheet) + + // 3. Child Stack inside Settings modal + let childRouter = NavigationRouter() + XCTAssertTrue(childRouter.path.isEmpty) + + childRouter.push(.general) + childRouter.push(.security) + childRouter.push(.advancedOptions) + XCTAssertEqual(childRouter.path.count, 3) + + // 4. Child pops one level + childRouter.dismiss() + XCTAssertEqual(childRouter.path, [.general, .security]) + + // 5. Child pops to root + childRouter.popToRoot() + XCTAssertTrue(childRouter.path.isEmpty) + + // 6. Parent dismisses modal sheet + parentRouter.dismiss() + XCTAssertNil(parentRouter.sheet) + // Parent stack remains untouched + XCTAssertEqual(parentRouter.path, [.feed]) + } + + /// Scenario: Two independent tabs have their own routers (e.g. Tab 1 vs Tab 2). + /// Mutating Tab 1 router must not cause any side-effects on Tab 2 router. + func testTabRoutersStateIsolation() { + let tab1Router = NavigationRouter() + let tab2Router = NavigationRouter() + + tab1Router.push(.feed) + tab1Router.push(.settings) + + XCTAssertEqual(tab1Router.path.count, 2) + XCTAssertTrue(tab2Router.path.isEmpty) + + tab2Router.push(.general) + XCTAssertEqual(tab2Router.path.count, 1) + + tab1Router.popToRoot() + XCTAssertTrue(tab1Router.path.isEmpty) + // Tab 2 must stay intact + XCTAssertEqual(tab2Router.path, [.general]) + } +} From 1cfb97c7177c487e9811fedd582b64a8b4c1fe1c Mon Sep 17 00:00:00 2001 From: iletai Date: Mon, 19 Oct 2026 23:16:13 +0700 Subject: [PATCH 05/22] docs: update example app and align readme with 2.0 api --- .../ViewNavigationTarget.swift | 74 ++++----- README.md | 156 +++++++++++------- 2 files changed, 123 insertions(+), 107 deletions(-) diff --git a/NavigationStackExample/NavigationStackExample/BaseDefineTarget/ViewNavigationTarget.swift b/NavigationStackExample/NavigationStackExample/BaseDefineTarget/ViewNavigationTarget.swift index a394cf7..987e604 100644 --- a/NavigationStackExample/NavigationStackExample/BaseDefineTarget/ViewNavigationTarget.swift +++ b/NavigationStackExample/NavigationStackExample/BaseDefineTarget/ViewNavigationTarget.swift @@ -10,29 +10,18 @@ import BaseNavigationStack import SwiftUI public enum ViewNavigationTarget: BaseViewProtocol { - public func withNavigationDestination() -> some View { - switch self { - case .policy(_): - PolicyView() - case .list: - ListView() - case .splash: - SplashView() - default: - EmptyView() - } - } - - public static func == (lhs: ViewNavigationTarget, rhs: ViewNavigationTarget) -> Bool { - lhs.id == rhs.id - } - + case splash + case main + case list + case policy(URL) + case updateProfile(userID: String) + public var id: String { switch self { - case .policy(_): - return "policy" - case .updateProfile(_): - return "updateProfile" + case .policy(let url): + return "policy-\(url.absoluteString)" + case .updateProfile(let id): + return "updateProfile-\(id)" case .splash: return "splash" case .main: @@ -42,29 +31,29 @@ public enum ViewNavigationTarget: BaseViewProtocol { } } - case splash - case main - case list - case policy(URL) - case updateProfile(() -> Void?) + public static func == (lhs: ViewNavigationTarget, rhs: ViewNavigationTarget) -> Bool { + lhs.id == rhs.id + } public func hash(into hasher: inout Hasher) { + hasher.combine(id) + } + + @MainActor + public func withNavigationDestination() -> some View { switch self { - case .splash: - hasher.combine("splash") - case .main: - hasher.combine("main") + case .policy(_): + PolicyView() case .list: - hasher.combine("list") - case .policy(let url): - hasher.combine("policy") - hasher.combine(url) - case .updateProfile(let closure): - hasher.combine("updateProfile") - hasher.combine(ObjectIdentifier(closure as AnyObject)) + ListView() + case .splash: + SplashView() + default: + EmptyView() } } + @MainActor public func withSheetDestination() -> some View { switch self { case .policy(_): @@ -81,6 +70,7 @@ public enum ViewNavigationTarget: BaseViewProtocol { } } + @MainActor public func withFullScreenDestination() -> some View { switch self { case .policy(_): @@ -96,15 +86,7 @@ public enum ViewNavigationTarget: BaseViewProtocol { public var detent: Set { switch self { - case .splash: - return [.large] - case .main: - return [.large] - case .list: - return [.large] - case .policy(_): - return [.large] - case .updateProfile(_): + case .splash, .main, .list, .policy, .updateProfile: return [.large] } } diff --git a/README.md b/README.md index ae50068..e726ab7 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,132 @@ -# BaseNavigationStack -Build a navigation controller with Navigation Stack SwiftUI +# BaseNavigationStack 2.0 -[![Swift Version](https://img.shields.io/badge/Swift-5.9-orange.svg)](https://swift.org) -[![Platform](https://img.shields.io/cocoapods/p/LFAlertController.svg?style=flat)](https://developer.apple.com/ios/) +Modern, type-safe, data-driven navigation controller for SwiftUI (iOS 17+ & macOS 14+). -BaseNavigationStack is a Swift package that provides a flexible and reusable base class for managing navigation stacks in SwiftUI applications. +[![Swift Version](https://img.shields.io/badge/Swift-6.0-orange.svg)](https://swift.org) +[![Platforms](https://img.shields.io/badge/Platforms-iOS%2017.0+%20%7C%20macOS%2014.0+-blue.svg)](https://developer.apple.com) +[![CI](https://github.com/iletai/BaseNavigationStack/actions/workflows/ci.yml/badge.svg)](https://github.com/iletai/BaseNavigationStack/actions) +[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) -## Overview +`BaseNavigationStack` simplifies navigation in SwiftUI by centralizing Stack pushes, Sheet modals, and FullScreenCover transitions under a single `@MainActor @Observable` state manager with **zero external dependencies**. -`BaseNavigationStack` is designed to simplify the management of navigation stacks in SwiftUI applications. It introduces a generic approach to handle different types for views and presentation targets. This allows you to build navigation flows with ease, supporting various types of views and presentation styles. +--- -## Example: +## Features -[