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?
Post
Replies
Boosts
Views
Activity
Thank you, the combination of isActive on NavigationLink and .onAppear together are what I had not understood.
With a couple of adaptations that will work nicely.
Most forums I frequent prefer pseudocode for brevity. I will remember that's not the case here - thanks for the heads up.
I think I have found my own answer now.
If you only define document types in your Info.plist with a CFBundleTypeRole of Viewer, then create your DocumentGroup like so:
DocumentGroup(viewing: MyDocument.self) { file in
ContentView(document: file.$document)
}
(Note the viewing label rather than newDocument)
Then your File menu will have the New item automatically disabled as there are no types defined which can create a document.
@Greigarious You are not the only one now, I've just hit this same problem!
Could you please let me know your feedback number so that I can file a duplicate?
Did you already include a sample project in that bug report? If not, I will do so.
Thank you for discussing the workaround, I will be making use of it for now.