How to preserve NavigationLink styling within List of buttons? #37
-
The last few episodes related to navigation in SwiftUI have been awesome, but every time a My question is, what would you recommend if someone wants to preserve that style while moving to I'm thinking about things like:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @rzulkoski, it definitely is a bummer. @tgrapperon has done a lot of work investigating a However, there is a quick "hack" one can do to use Button {
self.model.buttonTapped()
} label: {
NavigationLink(value: UUID()) {
Text("Go to screen")
}
}
.buttonStyle(.borderless) And you can further style the button in anyway you want. It's not so bad, and maybe we can even package it up in a nice API for the library some day. Or at the very least, document this pattern. |
Beta Was this translation helpful? Give feedback.
-
Hey @rzulkoski! This is indeed something lacking with the current official API's. It is relatively straightforward to build something that will look like a My most promising results were obtained doing the opposite of Brandon's suggestion, that is putting a So at the end of the day, I'm not 100% sure about the way to handle this problem. It is possible that something can be done, but it will require a considerable amount of work if one wants it to work across many platforms/os versions. I don't know if it's worth it, and if so, how far should we want to match the original features. Because we have more control/insight over the state of the application when using TCA, I decided to postpone work on this feature until TCA's navigation API settles. But it doesn't mean that nothing can be done in the meantime! Feel free to comment if you have new ideas to tackle the problem! |
Beta Was this translation helpful? Give feedback.
Hey @rzulkoski! This is indeed something lacking with the current official API's. It is relatively straightforward to build something that will look like a
NavigationLink
with a chevron at rest, using Brandon's trick, or an explicitButtonStyle
. It is however very tricky to produce something that behaves idiomatically.My most promising results were obtained doing the opposite of Brandon's suggestion, that is putting a
Button
in theNavigationLink's
Label
. I've posted them in the form of a self-contained gist. This is relatively hackish, but so is thisButtonStyle
approach from earlier this year or more recently. In both cases, it works reliably only on iOS, as we're able to introspect th…