From e974ce8ca0875c533674cd62d49d20891658a662 Mon Sep 17 00:00:00 2001 From: Shawn Date: Tue, 7 Nov 2023 11:12:05 -0700 Subject: [PATCH] Add support for new containerBackground API in iOS 17 --- .../WonderWidgetViewComponents.swift | 14 ++++++++++++++ ios/WonderousWidget/WonderousWidgetView.swift | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ios/WonderousWidget/WonderWidgetViewComponents.swift b/ios/WonderousWidget/WonderWidgetViewComponents.swift index 5b558a95..88d0cbc9 100644 --- a/ios/WonderousWidget/WonderWidgetViewComponents.swift +++ b/ios/WonderousWidget/WonderWidgetViewComponents.swift @@ -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) + } + } +} diff --git a/ios/WonderousWidget/WonderousWidgetView.swift b/ios/WonderousWidget/WonderousWidgetView.swift index 1d23ee3d..775953cf 100644 --- a/ios/WonderousWidget/WonderousWidgetView.swift +++ b/ios/WonderousWidget/WonderousWidgetView.swift @@ -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")) } }