Hi, I need to keep supporting iOS16 for my widgets. I'm having a problem using the iOS17 'containerBackground' API.
Ideally I would use a view extension:
extension View {
func adoptableWidgetBackground(_ color: Color) -> some View {
if #available(iOS 17.0, *) {
containerBackground(for: .widget) { color }
}
else {
background(color)
}
}
}
But this gives an error:
Branches have mismatching types 'some View' (result of 'Self.containerBackground(for:alignment:content:)') and 'some View' (result of 'Self.background(_:alignment:)')
If I try to use this directly on the 'body' view modifier like this:
if #available(iOS 17.0, *) {
.containerBackground(for: .widget) {
ContainerRelativeShape().fill(Color.init(UIColor.quaternarySystemFill))
}
} else {
.background(ContainerRelativeShape().fill(Color.init(UIColor.quaternarySystemFill)))
}
This doesn't work either.
Instance member 'containerBackground' cannot be used on type 'View'
How do I use this correctly?