Add support for new containerBackground API in iOS 17

This commit is contained in:
Shawn 2023-11-07 11:12:05 -07:00
parent 24d08a69e9
commit e974ce8ca0
2 changed files with 17 additions and 2 deletions

View File

@ -47,3 +47,17 @@ struct GaugeProgressStyle: ProgressViewStyle {
}
}
}
// Create an extension to support new containerBackground API on
// iOS 17 while still supporting iOS 16 and less (https://nemecek.be/blog/192/hotfixing-widgets-for-ios-17-containerbackground-padding)
extension View {
func widgetBackground(_ backgroundView: some View) -> some View {
if #available(iOSApplicationExtension 17.0, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}

View File

@ -55,14 +55,15 @@ struct WonderousWidgetView : View {
}
return ZStack{
Color.darkGrey
BgImage(entry: entry).opacity(0.8)
LinearGradient(
gradient: Gradient(colors: [.black.opacity(0), .black]),
startPoint: .center,
endPoint: .bottom)
content.padding(16)
}.widgetURL(URL(string: "wonderous:///collection"))
}
.widgetBackground(Color.darkGrey)
.widgetURL(URL(string: "wonderous:///collection"))
}
}