Search code examples
swiftuipopover

SwiftUI: present popover on iPhone?


I am looking at the Apple Reminders app and want to build the same pop over like view on iPhone. This the screen I am referring to:

enter image description here

So, I can present a popover like UI on an iPad using the popover modifier.

struct ContentView: View {
    // 1.
    @State var isPopoverPresented = false
    
    var body: some View {
        // 2.
        Button(action: {
            self.isPopoverPresented = true
        }) {
            Text("Some content")
        }
        // 3.
        .popover(isPresented: $isPopoverPresented) {
            Text("Popover is Presented")
                .font(.largeTitle)
                .frame(width: 200, height: 300)
        }
    }
}

However when that code runs on an iPhone, the popover turns in a fullscreen modal coming up from the bottom.

I want to know if there is a native way to build a screen like the one shown in the Reminders app or, is that screen a custom View with custom layout logic on an iPhone?


Solution

  • You're looking for a Menu (UIMenu in UIKit). Note that it's iOS 14+ only.