onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
669 stars 33 forks source link

How to use popover in SwiftUI #882

Open onmyway133 opened 2 years ago

onmyway133 commented 2 years ago

In SwiftUI, .popover shows as popover on Mac and iPad, but as .sheet on iPhone (compact size class)

We can use minWidth, minHeight to specify sizes on Mac and iPad. On iPhone, we can check and wrap it inside NavigationView. Setting navigationTitle without being embedded in NavigationView has not effect

``

.popover(isPresented: $showsEdit) {
    EditSnippetView(
        snippet: snippet
    )
    .frame(minWidth: 300, alignment: .topLeading)
    .navigationTitle("Tags")
    .modifier(
        EmbedInNavigationModifier()
    )
}