I want to create a popup menu like this
and it has a clear full screen overlay, when touch the overlay, popup menu will dismiss.
I tried add an overlay to root view, and add a menu list view to it, hardcoding position and frame for it, align with navigationItem then create a EnvironmentObject to store the overlay's toggle. After this, I arrived my goal, but I think it was kind of mechanical, so my question is, is there has a good way to do this? like just use view modifier, or another with less step?
This is my root view:
struct Root : View {
TabbedView {
NavigationView {
HomePage()
}
}.overlay(...) <-- add a overlay at root view.
}
struct HomePage : View {
var body: some View {
ZStack {
List {...}
}
.navigationBarTitle("Home")
.navigationBarItems(trailing:
Button(action: {
// show popup menu
}) {
Image(systemName: "plus.circle")
}
)
}
}