Thanks for the reply. I was hoping to find a solution that didn't involve maintaining a mapping of current and future (e.g. iPhone SE 2 was released after iPhone X but has a touch ID sensor) devices just to update the spacing. I'm curious if anyone has run into this specific problem before and if they just regularly update a list of which phones have touch ID vs. not.
I've played around around with this solution which is a little clunky but seems to work:
let button = Button {} label: {
Text("Button")
}
if UIApplication.shared.windows.first?.safeAreaInsets.bottom == 0 {
button.padding(.bottom)
} else {
button
}
Basically if there's no space at the bottom of the window, add bottom padding. I factored it out into a separate modifier:
struct SafeAreaBottomPadding: ViewModifier {
func body(content: Content) -> some View {
if UIApplication.shared.windows.first?.safeAreaInsets.bottom == 0 {
content.padding(.bottom)
} else {
content
}
}
}
extension View {
func safeAreaBottomPadding() -> some View {
modifier(SafeAreaBottomPadding())
}
}
Which I can use like this:
button.safeAreaBottomPadding()
Generally SwiftUI is pretty good about default spacing in a variety of contexts so I was hoping there was a more idiomatic solution / I'm not sure if there any caveats to this approach, but in my limited testing it seems work.