Skip to content

Commit

Permalink
Merge pull request #10 from davidscheutz/remove-any-view
Browse files Browse the repository at this point in the history
Remove AnyView requirement for root view and destinations view builder
  • Loading branch information
davidscheutz authored May 11, 2024
2 parents 6cddf63 + da404fb commit 4160994
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/InfiniteNavigation/Helper/View+Environments.swift
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
12 changes: 6 additions & 6 deletions Sources/InfiniteNavigation/InfiniteNavContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ 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]
public typealias Environment = any ObservableObject

@available(iOS 16.0, *)
public struct InfiniteNavContainer<Destination: Hashable, Root: View>: View {

public typealias NavDestinationPublisher = AnyPublisher<NavAction<Destination>, Never>
public typealias NavDestinationBuilder = (Destination) -> AnyView
public typealias NavDestinationBuilder = (Destination) -> any 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
) {
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions Sources/InfiniteNavigation/InfiniteNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public struct InfiniteNavigation {
public static func create<Root: View, Destination: Hashable>(
initialStack: [Destination] = [],
navAction: AnyPublisher<NavAction<Destination>, Never>,
environments: any ObservableObject...,
viewBuilder: @escaping (Destination) -> AnyView,
root: @escaping () -> Root
environments: Environment...,
viewBuilder: @escaping (Destination) -> some View,
@ViewBuilder root: @escaping () -> Root
) -> some View {
create(
initialStack: initialStack,
Expand All @@ -24,9 +24,9 @@ public struct InfiniteNavigation {
public static func create<Root: View, Destination: Hashable>(
initialStack: [Destination] = [],
navAction: AnyPublisher<NavAction<Destination>, Never>,
environments: Environments = [],
viewBuilder: @escaping (Destination) -> AnyView,
root: @escaping () -> Root
environments: [Environment] = [],
viewBuilder: @escaping (Destination) -> some View,
@ViewBuilder root: @escaping () -> Root
) -> some View {
if #available(iOS 16.0, *) {
InfiniteNavContainer(
Expand Down
8 changes: 4 additions & 4 deletions Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct LegacyInfiniteNavContainer<Root: SwiftUI.View, View>: UIViewContro

public typealias UIViewControllerType = UINavigationController
public typealias NavDestinationPublisher = AnyPublisher<NavAction<View>, Never>
public typealias NavDestinationBuilder = (View) -> AnyView
public typealias NavDestinationBuilder = (View) -> any SwiftUI.View

private let coordinator: Coordinator
private let rootResolver: () -> Root
Expand All @@ -17,7 +17,7 @@ public struct LegacyInfiniteNavContainer<Root: SwiftUI.View, View>: UIViewContro
internal init(
initialStack: [View] = [],
navAction: NavDestinationPublisher,
environments: Environments = [],
environments: [Environment] = [],
viewBuilder: @escaping NavDestinationBuilder,
root: @escaping () -> Root
) {
Expand Down Expand Up @@ -50,11 +50,11 @@ public struct LegacyInfiniteNavContainer<Root: SwiftUI.View, View>: 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

Expand Down

0 comments on commit 4160994

Please sign in to comment.