How do I navigate to a new page programmatically from the user choosing an action on the Menu
view in SwiftUI? What I have here isn't navigating when I choose an option.
Example Code:
struct MenuView: View {
@State var oneActive: Bool = false
@State var twoActive: Bool = false
var body: some View {
Menu {
Button {
oneActive = true
} label: {
Text("Option One")
}
Button {
twoActive = true
} label: {
Text("Option Two")
}
} label: {
Image(systemName: "ellipsis")
}
NavigationLink(destination: Text("Option One View"), isActive: $oneActive) { EmptyView() }
NavigationLink(destination: Text("Option Two View"), isActive: $twoActive) { EmptyView() }
}
}
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
ScrollView {
ForEach(0..<100, id: \.self) { index in
Text("\(index)")
}
}
}
.navigationTitle("TItle")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
MenuView()
}
}
}
}
}