Sorry, I was trying to make the example as easy to follow as possible, apparently that backfired.
Here's more code:
Root view:
struct ContentView {
var body: some View {
List {
NavigationLink(destination: AnimalListView()) {
SummaryView()
}
}
}
}
Summary view:
struct SummaryView {
var body: some View {
HStack {
VStack {
Text("24")
Text("Dogs")
}
}
HStack {
VStack {
Text("24")
Text("Cats")
}
}
}
}
AnimalListView:
struct AnimalListView {
enum AnimalType {
case cat
case dog
case allAnimals
}
@State var animalType: AnimalType
var body: some View {
// list animals of selected type
}
}
By filter already set, I mean that I want to have animalType set to .allAnimals if the user taps on the row background, or a specific animal type if the user taps on the Text items in the summaryView. ie, the user taps on "24 Dogs", so the detail view should filter on .dog
Your third point is the basically the essence of my question. What is a sensible way to get the info of what the user tapped from SummaryView up into my ContentView so that the information can be used to set the filter when navigating to the AnimalListView?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: