I am building a SwiftUI app where I have an overlay that is conditionally shown across my entire application like this:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
.safeAreaInset(edge: .bottom) {
Group {
if myCondition {
EmptyView()
} else {
OverlayView()
}
}
}
}
}
}
I would expect this to adjust the safe area insets of the NavigationView
and propagate it to any content view, so content is not stuck under the overlay. At least that's how additionalSafeAreaInsets
in UIKit would behave. Unfortunately, it seems that SwiftUI ignores any safeAreaInsets()
on a NavigationView
(the overlay will show up, but safe area is not adjusted).
While I can use a GeometryReader
to read the overlay size and then set safeAreaInsets()
on ContentView
, this will only work for ContentView
- as soon as I navigate to the next view the safe area is gone.
Is there any nice way to get NavigationView to accept additional safe area insets, either by using safeAreaInsets()
or by some other way?