NavigationStack suggestions

This is a very very welcome feature, thanks!

Namings

  • NavigationStack-> NavigationView
  • NavigationPath -> NavigationStack
  • path (parameter) -> stack

”NavigationView” name is more consistently with TabView, NavigationSplitView but I understand for compatibility.

Also “stack” is most correct name than “path”.

EnvironmentValue

Include a NavigationPath to the EnvironmentValues, uses when we don’t set NavigationStack(binding parameter).

This works for 98% of use cases, we don’t want to binding the path to every children (and deep children, …). If someone want custom case they will use the specific parameter.

NavigationPath Common Operators

Like pop to root and replace last.

Another suggestion.

In many cases we don’t use the NavigationLink because we have a custom UI and can’t change de pressed style. Will be great to have a “NavigationLinkStyle” (with isPressed) or a NavigationButton or data-drive push capabilities for the Button.

In fact Button is used for push all the time.

Another suggestion.

Example from docs:

NavigationStack {
    List(parks) { park in
        NavigationLink(park.name, value: park)
    }
    .navigationDestination(for: Park.self) { park in
        ParkDetails(park: park)
    }
}

In this case, we are duplicating the “park” data because that park is already in the stack. The navigation stack contains the park and we are making an unnecessary copy for ParkDetails view.

Why not to use the @Environment to get the pushed value (in this case the park) on ParkDetail? Every pushed View most have the corresponding value available in the @Environment.

Before:

struct ParkDetail: View {
    let park: Park
}

After:

struct ParkDetail: View {
    @Environment(\.pushedData) var park: Park
}

Also we can do the same for other cases like modals:

struct ParkPreview: View {
    @Environment(\.presentedData) var park: Park
}

Another thing that could be change is the need for Hashable, why not use the Identifiable like sheet / fullscreenCover?! SwiftUI is turning model object more and more dependent on the view needs.

Before SwiftUI:

struct Product: Codable { … }

After SwiftUI: (we need for ForEach and sheet / fullscreenCover, ok makes sense, any object should have an id)

struct Product: Codable, Identifiable { … }

After SwiftUI 4.0: (we need for NavigationStack push item)

struct Product: Codable, Identifiable, Hashable { … }

Bonus: (if we need to use the onChange)

struct Product: Codable, Identifiable, Hashable, Equatable { … }

It seems that now (iOS 16) we can apply button styles to NavigationLink.

NavigationLink("Show Terms") {
    TermsView()
}
.buttonStyle(.borderedProminent)
.controlSize(.large)

I don’t know if is iOS 16 only or not but this is huge improvement. Thanks

NavigationStack suggestions
 
 
Q