Hi,
Is there a way of specifying a destination for a NavigationLink that is passed as init parameter?
I have this code:
struct RowLine: View {
var text: String
var imageName: String
var body: some View {
NavigationLink(destination: text == "Settings" ? SettingsView() : MyInfoView()){
HStack{
Image(systemName: imageName)
Text(text)
}
}
}
}
And my intention is to have, instead of the ternary operator in the destination parameter, directly the view that I passed as parameter at init.
For example, call the view like this:
RowLine(text: "Settings", imageName: "gearshape", nextView: myNextView())
And the view remains like this:
struct RowLine: View {
var text: String
var imageName: String
var nextView: View /*Of course, this is ilegal*/
var body: some View {
NavigationLink(destination: nextView){
HStack{
Image(systemName: imageName)
Text(text)
}
}
}
}
With this approach, I can have multiple items in a list with different destination but with the same codebase.
Thank you so much.
F.
Selecting any option will automatically load the page