Skip to content

Commit

Permalink
improve environment type
Browse files Browse the repository at this point in the history
  • Loading branch information
David Scheutz committed Feb 27, 2024
1 parent 51c9400 commit da404fb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 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
6 changes: 3 additions & 3 deletions Sources/InfiniteNavigation/InfiniteNavContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Destination: Hashable, Root: View>: View {
Expand All @@ -18,14 +18,14 @@ public struct InfiniteNavContainer<Destination: Hashable, Root: View>: 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
4 changes: 2 additions & 2 deletions Sources/InfiniteNavigation/InfiniteNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct InfiniteNavigation {
public static func create<Root: View, Destination: Hashable>(
initialStack: [Destination] = [],
navAction: AnyPublisher<NavAction<Destination>, Never>,
environments: any ObservableObject...,
environments: Environment...,
viewBuilder: @escaping (Destination) -> some View,
@ViewBuilder root: @escaping () -> Root
) -> some View {
Expand All @@ -24,7 +24,7 @@ public struct InfiniteNavigation {
public static func create<Root: View, Destination: Hashable>(
initialStack: [Destination] = [],
navAction: AnyPublisher<NavAction<Destination>, Never>,
environments: Environments = [],
environments: [Environment] = [],
viewBuilder: @escaping (Destination) -> some View,
@ViewBuilder root: @escaping () -> Root
) -> some View {
Expand Down
6 changes: 3 additions & 3 deletions Sources/InfiniteNavigation/LegacyInfiniteNavContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 da404fb

Please sign in to comment.