Replies: 2 comments 2 replies
-
|
As has been pointed out, the NavigationDestination protocol specifies the mechanism by which destination enumerations provides views for pushed and presented values. It also provides the for determining the method used by This opinionated mechanism is one of the core foundations on which Navigator is based, and won't change. That said, I can update the signature for "which has no mandatory requirements for the parameter types of routes" That's incorrect. NavigationLink(value:label:) requires that value be Hashable. The .sheet and .cover presentation bindings require conformance to Identifiable. Might mention that navigation send also simply uses Hashable values. |
Beta Was this translation helpful? Give feedback.
-
Translated with DeepL.com (free version) public extension Navigator {
@MainActor
func present(sheet: any Hashable) {
if let sheet = sheet as? (any NavigationDestination) {
navigate(to: sheet, method: .sheet)
} else {
fatalError("The sheet item must conform to NavigationDestination!")
}
}
@MainActor
func present(cover: any Hashable) {
if let cover = cover as? (any NavigationDestination) {
navigate(to: cover, method: .cover)
} else {
fatalError("The cover item must conform to NavigationDestination!")
}
}
@MainActor
func push(_ destination: any Hashable) {
if let destination = destination as? (any NavigationDestination) {
push(destination)
} else {
fatalError("The cover item must conform to NavigationDestination!")
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I'm having a problem using your framework.
My project consists of many small swift packages. I define a Router package, and define a route enum in it. But I did not implement the NavigationDestination protocol in this package, because the Router package is a very underlying library and it has no idea about the specific page. I implemented NavigationDestination in the main project and implemented the specific page corresponding to the route.
However, when I try to use the navigate API in the mid-level packages, it is discovered that navigate must accept a routing parameter that implements the
NavigationDestinationprotocol. I think this requirement is not conducive to componentization. Although forced types can avoid unnecessary errors, it binds the definition and implementation together. It is recommended to refer to the system's APINavigationLink, which has no mandatory requirements for the parameter types of routes, and your Navigator itself also supports this API.Beta Was this translation helpful? Give feedback.
All reactions