From 5eb08b2507ba93c9f38a8c8faf134d2920621143 Mon Sep 17 00:00:00 2001 From: Zaphod Beeblebrox Date: Fri, 17 May 2024 20:19:02 +0200 Subject: [PATCH] Patch 0.4.1 chore: - Minor code refactoring --- README.md | 6 ++++++ Sources/Internal/Managers/NavigationManager.swift | 2 -- Sources/Internal/Views/NavigationStackView.swift | 11 ++--------- Sources/Internal/Views/NavigationView.swift | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 763b1f4..d4815c5 100644 --- a/README.md +++ b/README.md @@ -181,8 +181,12 @@ Navigattie is released under the MIT license. See [LICENSE][License] for details # Our other open source SwiftUI libraries [PopupView] - The most powerful popup library that allows you to present any popup
+[CalendarView] - Create your own calendar object in no time +
[GridView] - Lay out your data with no effort
+[CameraView] - The most powerful CameraController. Designed for SwiftUI +
[Timer] - Modern API for Timer @@ -194,5 +198,7 @@ Navigattie is released under the MIT license. See [LICENSE][License] for details [License]: https://github.com/Mijick/Navigattie/blob/main/LICENSE [PopupView]: https://github.com/Mijick/PopupView +[CalendarView]: https://github.com/Mijick/CalendarView +[CameraView]: https://github.com/Mijick/CameraView [GridView]: https://github.com/Mijick/GridView [Timer]: https://github.com/Mijick/Timer diff --git a/Sources/Internal/Managers/NavigationManager.swift b/Sources/Internal/Managers/NavigationManager.swift index ae0a64b..90a1e4a 100644 --- a/Sources/Internal/Managers/NavigationManager.swift +++ b/Sources/Internal/Managers/NavigationManager.swift @@ -28,7 +28,6 @@ public class NavigationManager: ObservableObject { @Published private(set) var transitionsBlocked: Bool = false private(set) var transitionType: TransitionType = .push private(set) var transitionAnimation: TransitionAnimation = .no - private(set) var namespace: Namespace.ID? static let shared: NavigationManager = .init() private init() {} @@ -49,7 +48,6 @@ private extension NavigationManager { // MARK: - Setters extension NavigationManager { static func setRoot(_ rootView: some NavigatableView) { DispatchQueue.main.async { shared.views = [.init(rootView, .no)] }} - static func setNamespace(_ value: Namespace.ID) { if shared.namespace == nil { shared.namespace = value } } static func blockTransitions(_ value: Bool) { shared.transitionsBlocked = value } } diff --git a/Sources/Internal/Views/NavigationStackView.swift b/Sources/Internal/Views/NavigationStackView.swift index f780f43..fb4185d 100644 --- a/Sources/Internal/Views/NavigationStackView.swift +++ b/Sources/Internal/Views/NavigationStackView.swift @@ -20,21 +20,14 @@ struct NavigationStackView: View { private let config: NavigationGlobalConfig - init(namespace: Namespace.ID, config: NavigationGlobalConfig) { self._temporaryViews = .init(initialValue: NavigationManager.shared.views); self.config = config; NavigationManager.setNamespace(namespace) } + init(config: NavigationGlobalConfig) { self._temporaryViews = .init(initialValue: NavigationManager.shared.views); self.config = config } var body: some View { - ZStack(content: createStack) + ZStack { ForEach(temporaryViews, id: \.id, content: createItem) } .ignoresSafeArea(.container) .onChange(of: stack.views, perform: onViewsChanged) .onAnimationCompleted(for: animatableOpacity, perform: onAnimationCompleted) } } - -private extension NavigationStackView { - func createStack() -> some View { - ForEach(temporaryViews, id: \.id, content: createItem) - } -} - private extension NavigationStackView { func createItem(_ item: AnyNavigatableView) -> some View { item diff --git a/Sources/Internal/Views/NavigationView.swift b/Sources/Internal/Views/NavigationView.swift index 58b6096..13c7191 100644 --- a/Sources/Internal/Views/NavigationView.swift +++ b/Sources/Internal/Views/NavigationView.swift @@ -11,10 +11,9 @@ import SwiftUI struct NavigationView: View { - @Namespace var namespace private let config: NavigationGlobalConfig init(rootView: some NavigatableView, config: NavigationGlobalConfig?) { self.config = config ?? .init(); NavigationManager.setRoot(rootView) } - var body: some View { NavigationStackView(namespace: namespace, config: config) } + var body: some View { NavigationStackView(config: config) } }