SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.24k stars 741 forks source link

SwiftUI View ignoresSafeArea #529

Closed xiaoxidong closed 9 months ago

xiaoxidong commented 9 months ago

For the bottom card most time need ignoresSafeArea, maybe a config for ignoresSafeArea?

wtmoose commented 9 months ago

Could you provide a screenshot + code that demonstrates the issue you're having?

xiaoxidong commented 9 months ago

1 Just the SwiftUI demo project.

wtmoose commented 9 months ago

I'm assuming you want the background to extend to the edge of the screen, but you don't want your content within the safe area. You can do that with a mask. For example, I've modified the demo app to use a mask that rounds the bottom corners and ignores the top safe area:

var body: some View {
    VStack(alignment: .leading) {
        Text(message.title).font(.system(size: 20, weight: .bold))
        Text(message.body)
    }
    .multilineTextAlignment(.leading)
    .padding(30)
    .frame(maxWidth: .infinity)
    .background(.demoMessageBackground)
    .mask(
        UnevenRoundedRectangle(
            cornerRadii: .init(bottomLeading: 15, bottomTrailing: 15)
        )
        .edgesIgnoringSafeArea(.top)
    )
}

This produces the result below. Putting your content in the safe area would require overriding the safe area insets of MessageHostingView, which isn't currently supported. However, I'm adding something to make edge styling easier and may add support for that as well.

Does this resolve your issue?

image

xiaoxidong commented 9 months ago

Great, Thank you so much.