The below provides a quick and simple solution:
private struct _ShowsWidgetContainerBackground: EnvironmentKey {
static let defaultValue: Bool = true
}
extension EnvironmentValues {
var showsWidgetContainerBackgroundWithFallback: Bool {
get {
if #available(iOSApplicationExtension 17.0, *) {
self.showsWidgetContainerBackground
} else {
self[_ShowsWidgetContainerBackground.self]
}
}
set {}
}
}
You can use the new environment key showsWidgetContainerBackgroundWithFallback in place of showsWidgetContainerBackground.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: