Skip to content

Instantly share code, notes, and snippets.

@agiletortoise
Created July 31, 2023 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agiletortoise/ba276c346b6528bee62235a48860d7aa to your computer and use it in GitHub Desktop.
Save agiletortoise/ba276c346b6528bee62235a48860d7aa to your computer and use it in GitHub Desktop.
Useful way to provide backward compatible widget backgrounds
extension View {
@ViewBuilder
func widgetBackground<V>(@ViewBuilder content: () -> V) -> some View where V : View {
if #available(macOSApplicationExtension 14.0, iOSApplicationExtension 17.0, *) {
containerBackground(for: .widget) {
content()
}
} else {
background {
content()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment