Presenting Popovers in SwiftUI
Find out in this quick post how to present a popover in SwiftUI, what’s important to remember, and what you should be expecting from it.
Popover is a system provided control used widely in applications running both in iPad and Mac. It allows to display additional content or ask for user interaction in a concise and elegant fashion; most importantly, users are familiar with it, so it is easy for them to use popovers.
Presenting a popover in SwiftUI hides no tricky parts, and it’s quite similar to the way alerts are presented. That means that there is a specific view modifier to call in order to display it, as well as to provide a few configuration options. Note that popovers show up as alerts in iPhone; they are meant for iPad and Mac devices only.
Presenting a popover
Suppose that we have the following simple button implementation in SwiftUI:
The goal here is to display a popover when the button gets tapped in order to show…