Home > Software design >  How to ignore safe area for container and respect safe area for content in swift UI
How to ignore safe area for container and respect safe area for content in swift UI

Time:06-08

I'm trying to create a bottom sheet in swift ui that looks something like this

Bottom sheet closed Bottom sheet open Bottom sheet open and textfield is selected, keyboard is active

CodePudding user response:

Actually instead of ignoring safe area for everything (that results in issue), we need it only in background, so the question is how to correctly construct background in this case.

Note: the .cornerRadius is also not appropriate here, because it clips content

demo

Here is a main part of a fix. Tested with Xcode 13.4 / iOS 15.5

.background(
    RoundedRectangle(cornerRadius: Constants.radius)  // corners !!
        .fill(.white)                                 // background !!
        .edgesIgnoringSafeArea([.bottom, .horizontal]) // << only here !!
)

Complete test module is here

  • Related