Bläddra i källkod

fix widget iOS 17

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 år sedan
förälder
incheckning
99275c83bb

+ 1 - 0
Widget/Dashboard/DashboardWidgetView.swift

@@ -192,6 +192,7 @@ struct DashboardWidgetView: View {
                 .frame(maxWidth: geo.size.width, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
             }
         }
+        .widgetBackground(Color(UIColor.systemBackground))
     }
 }
 

+ 1 - 0
Widget/Files/FilesWidgetView.swift

@@ -182,6 +182,7 @@ struct FilesWidgetView: View {
                 .frame(maxWidth: geo.size.width, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
             }
         }
+        .widgetBackground(Color(UIColor.systemBackground))
     }
 }
 

+ 3 - 0
Widget/Lockscreen/LockscreenWidgetView.swift

@@ -43,6 +43,7 @@ struct LockscreenWidgetView: View {
                     }
                 )
                 .gaugeStyle(.accessoryCircularCapacity)
+                .widgetBackground(Color.clear)
             } else {
                 Gauge(
                     value: entry.quotaRelative,
@@ -56,6 +57,7 @@ struct LockscreenWidgetView: View {
                 )
                 .gaugeStyle(.accessoryCircular)
                 .redacted(reason: entry.isPlaceholder ? .placeholder : [])
+                .widgetBackground(Color.clear)
             }
         case .accessoryRectangular:
             VStack(alignment: .leading, spacing: 1) {
@@ -84,6 +86,7 @@ struct LockscreenWidgetView: View {
             }
             .widgetURL(entry.link)
             .redacted(reason: entry.isPlaceholder ? .placeholder : [])
+            .widgetBackground(Color.clear)
         default:
             Text("Not implemented")
         }

+ 1 - 3
Widget/Toolbar/ToolbarWidgetView.swift

@@ -41,9 +41,6 @@ struct ToolbarWidgetView: View {
 
             ZStack(alignment: .topLeading) {
 
-                Color(.black).opacity(0.9)
-                    .ignoresSafeArea()
-
                 HStack(spacing: 0) {
 
                     let sizeButton: CGFloat = 65
@@ -114,6 +111,7 @@ struct ToolbarWidgetView: View {
                 .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
             }
         }
+        .widgetBackground(Color.black.opacity(0.9))
     }
 }
 

+ 16 - 0
Widget/Widget.swift

@@ -47,6 +47,7 @@ struct DashboardWidget: Widget {
         .supportedFamilies([.systemLarge])
         .configurationDisplayName("Dashboard")
         .description(NSLocalizedString("_description_dashboardwidget_", comment: ""))
+        .contentMarginsDisabled()
     }
 }
 
@@ -60,6 +61,7 @@ struct FilesWidget: Widget {
         .supportedFamilies([.systemLarge])
         .configurationDisplayName("Files")
         .description(NSLocalizedString("_description_fileswidget_", comment: ""))
+        .contentMarginsDisabled()
     }
 }
 
@@ -73,6 +75,7 @@ struct ToolbarWidget: Widget {
         .supportedFamilies([.systemMedium])
         .configurationDisplayName("Toolbar")
         .description(NSLocalizedString("_description_toolbarwidget_", comment: ""))
+        .contentMarginsDisabled()
     }
 }
 
@@ -87,8 +90,21 @@ struct LockscreenWidget: Widget {
             .supportedFamilies([.accessoryRectangular, .accessoryCircular])
             .configurationDisplayName(NSLocalizedString("_title_lockscreenwidget_", comment: ""))
             .description(NSLocalizedString("_description_lockscreenwidget_", comment: ""))
+            .contentMarginsDisabled()
         } else {
             return EmptyWidgetConfiguration()
         }
     }
 }
+
+extension View {
+    func widgetBackground(_ backgroundView: some View) -> some View {
+        if #available(iOSApplicationExtension 17.0, *) {
+            return containerBackground(for: .widget) {
+                backgroundView
+            }
+        } else {
+            return background(backgroundView)
+        }
+    }
+}