From ac7a0271c899f9ed47c7fffd01a3d5fad669320c Mon Sep 17 00:00:00 2001 From: David Scheutz Date: Tue, 27 Feb 2024 16:24:04 -0500 Subject: [PATCH 1/3] make root view completion a ViewBuilder --- Sources/InfiniteNavigation/InfiniteNavigation.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/InfiniteNavigation/InfiniteNavigation.swift b/Sources/InfiniteNavigation/InfiniteNavigation.swift index 1b990d3..26c8d1e 100644 --- a/Sources/InfiniteNavigation/InfiniteNavigation.swift +++ b/Sources/InfiniteNavigation/InfiniteNavigation.swift @@ -9,7 +9,7 @@ public struct InfiniteNavigation { navAction: AnyPublisher, Never>, environments: any ObservableObject..., viewBuilder: @escaping (Destination) -> AnyView, - root: @escaping () -> Root + @ViewBuilder root: @escaping () -> Root ) -> some View { create( initialStack: initialStack, @@ -26,7 +26,7 @@ public struct InfiniteNavigation { navAction: AnyPublisher, Never>, environments: Environments = [], viewBuilder: @escaping (Destination) -> AnyView, - root: @escaping () -> Root + @ViewBuilder root: @escaping () -> Root ) -> some View { if #available(iOS 16.0, *) { InfiniteNavContainer( From 51c94007a9f2f75d3c023849cf335810277a5572 Mon Sep 17 00:00:00 2001 From: David Scheutz Date: Tue, 27 Feb 2024 16:29:13 -0500 Subject: [PATCH 2/3] remove AnyView requirement --- Sources/InfiniteNavigation/InfiniteNavContainer.swift | 6 +++--- Sources/InfiniteNavigation/InfiniteNavigation.swift | 4 ++-- Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/InfiniteNavigation/InfiniteNavContainer.swift b/Sources/InfiniteNavigation/InfiniteNavContainer.swift index 95b8595..cc5261b 100644 --- a/Sources/InfiniteNavigation/InfiniteNavContainer.swift +++ b/Sources/InfiniteNavigation/InfiniteNavContainer.swift @@ -5,7 +5,7 @@ import Combine internal struct Sheet: Identifiable { let id = UUID().uuidString var path = NavigationPath() - let source: () -> AnyView + let source: () -> any View } public typealias Environments = [any ObservableObject] @@ -14,7 +14,7 @@ public typealias Environments = [any ObservableObject] public struct InfiniteNavContainer: View { public typealias NavDestinationPublisher = AnyPublisher, Never> - public typealias NavDestinationBuilder = (Destination) -> AnyView + public typealias NavDestinationBuilder = (Destination) -> any View private let navAction: NavDestinationPublisher private let viewBuilder: NavDestinationBuilder @@ -83,7 +83,7 @@ extension InfiniteNavContainer { .toAnyView() } - private func wrap(_ view: some View) -> some View { + private func wrap(_ view: any View) -> some View { view .apply(environments: environments) .navigationBarHidden(true) diff --git a/Sources/InfiniteNavigation/InfiniteNavigation.swift b/Sources/InfiniteNavigation/InfiniteNavigation.swift index 26c8d1e..2a850d8 100644 --- a/Sources/InfiniteNavigation/InfiniteNavigation.swift +++ b/Sources/InfiniteNavigation/InfiniteNavigation.swift @@ -8,7 +8,7 @@ public struct InfiniteNavigation { initialStack: [Destination] = [], navAction: AnyPublisher, Never>, environments: any ObservableObject..., - viewBuilder: @escaping (Destination) -> AnyView, + viewBuilder: @escaping (Destination) -> some View, @ViewBuilder root: @escaping () -> Root ) -> some View { create( @@ -25,7 +25,7 @@ public struct InfiniteNavigation { initialStack: [Destination] = [], navAction: AnyPublisher, Never>, environments: Environments = [], - viewBuilder: @escaping (Destination) -> AnyView, + viewBuilder: @escaping (Destination) -> some View, @ViewBuilder root: @escaping () -> Root ) -> some View { if #available(iOS 16.0, *) { diff --git a/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift b/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift index 91f2bee..a7be2d2 100644 --- a/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift +++ b/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift @@ -6,7 +6,7 @@ public struct LegacyInfiniteNavContainer: UIViewContro public typealias UIViewControllerType = UINavigationController public typealias NavDestinationPublisher = AnyPublisher, Never> - public typealias NavDestinationBuilder = (View) -> AnyView + public typealias NavDestinationBuilder = (View) -> any SwiftUI.View private let coordinator: Coordinator private let rootResolver: () -> Root From da404fbfbd3a381e4230b7c08eda37bcaa835e1a Mon Sep 17 00:00:00 2001 From: David Scheutz Date: Tue, 27 Feb 2024 16:41:37 -0500 Subject: [PATCH 3/3] improve environment type --- Sources/InfiniteNavigation/Helper/View+Environments.swift | 2 +- Sources/InfiniteNavigation/InfiniteNavContainer.swift | 6 +++--- Sources/InfiniteNavigation/InfiniteNavigation.swift | 4 ++-- Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/InfiniteNavigation/Helper/View+Environments.swift b/Sources/InfiniteNavigation/Helper/View+Environments.swift index d359a62..14a521b 100644 --- a/Sources/InfiniteNavigation/Helper/View+Environments.swift +++ b/Sources/InfiniteNavigation/Helper/View+Environments.swift @@ -1,7 +1,7 @@ import SwiftUI extension View { - func apply(environments: Environments) -> AnyView { + func apply(environments: [Environment]) -> AnyView { var result: any View = self environments.forEach { result = (result.environmentObject($0) as any View) } return result.toAnyView() diff --git a/Sources/InfiniteNavigation/InfiniteNavContainer.swift b/Sources/InfiniteNavigation/InfiniteNavContainer.swift index cc5261b..51cd1c2 100644 --- a/Sources/InfiniteNavigation/InfiniteNavContainer.swift +++ b/Sources/InfiniteNavigation/InfiniteNavContainer.swift @@ -8,7 +8,7 @@ internal struct Sheet: Identifiable { let source: () -> any View } -public typealias Environments = [any ObservableObject] +public typealias Environment = any ObservableObject @available(iOS 16.0, *) public struct InfiniteNavContainer: View { @@ -18,14 +18,14 @@ public struct InfiniteNavContainer: View { private let navAction: NavDestinationPublisher private let viewBuilder: NavDestinationBuilder - private let environments: Environments + private let environments: [Environment] @State private var stack: [Sheet] init( initialStack: [Destination] = [], navAction: NavDestinationPublisher, - environments: Environments = [], + environments: [Environment] = [], viewBuilder: @escaping NavDestinationBuilder, root: @escaping () -> Root ) { diff --git a/Sources/InfiniteNavigation/InfiniteNavigation.swift b/Sources/InfiniteNavigation/InfiniteNavigation.swift index 2a850d8..c4968ad 100644 --- a/Sources/InfiniteNavigation/InfiniteNavigation.swift +++ b/Sources/InfiniteNavigation/InfiniteNavigation.swift @@ -7,7 +7,7 @@ public struct InfiniteNavigation { public static func create( initialStack: [Destination] = [], navAction: AnyPublisher, Never>, - environments: any ObservableObject..., + environments: Environment..., viewBuilder: @escaping (Destination) -> some View, @ViewBuilder root: @escaping () -> Root ) -> some View { @@ -24,7 +24,7 @@ public struct InfiniteNavigation { public static func create( initialStack: [Destination] = [], navAction: AnyPublisher, Never>, - environments: Environments = [], + environments: [Environment] = [], viewBuilder: @escaping (Destination) -> some View, @ViewBuilder root: @escaping () -> Root ) -> some View { diff --git a/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift b/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift index a7be2d2..d5eac1c 100644 --- a/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift +++ b/Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift @@ -17,7 +17,7 @@ public struct LegacyInfiniteNavContainer: UIViewContro internal init( initialStack: [View] = [], navAction: NavDestinationPublisher, - environments: Environments = [], + environments: [Environment] = [], viewBuilder: @escaping NavDestinationBuilder, root: @escaping () -> Root ) { @@ -50,11 +50,11 @@ public struct LegacyInfiniteNavContainer: UIViewContro var resolver: Resolver? - private let environments: Environments + private let environments: [Environment] private let viewBuilder: NavDestinationBuilder private var navSubscription: AnyCancellable? - init(navAction: NavDestinationPublisher, environments: Environments, viewBuilder: @escaping NavDestinationBuilder) { + init(navAction: NavDestinationPublisher, environments: [Environment], viewBuilder: @escaping NavDestinationBuilder) { self.environments = environments self.viewBuilder = viewBuilder