diff --git a/Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift b/Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift index 98d32b6..4d48d8e 100644 --- a/Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift +++ b/Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift @@ -6,6 +6,10 @@ extension View { public func containerBackgroundForWidgetCompability(background: @escaping () -> Background) -> some View where Background: View { modifier(ContainerBackgroundForWidgetCompabilityModifier(background: background)) } + + public func containerBackgroundForWidget(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View { + modifier(ContainerBackgroundForWidgetModifier(background: background)) + } } struct ContainerBackgroundForWidgetCompabilityModifier: ViewModifier where Background: View { @@ -23,3 +27,23 @@ struct ContainerBackgroundForWidgetCompabilityModifier: ViewModifier } } } + +struct ContainerBackgroundForWidgetModifier: ViewModifier where Background: View { + + let background: () -> Background + + func body(content: Content) -> some View { + if #available(iOS 17.0, iOSApplicationExtension 17.0, watchOS 10.0, watchOSApplicationExtension 10.0, macOS 14.0, *) { + content + .containerBackground(for: .widget) { + background() + } + } else { + ZStack { + background() + content + .padding() + } + } + } +} \ No newline at end of file diff --git a/Sources/SwiftUIExtension/Extensions/ViewExtension.swift b/Sources/SwiftUIExtension/Extensions/ViewExtension.swift index 554bcf1..6945505 100644 --- a/Sources/SwiftUIExtension/Extensions/ViewExtension.swift +++ b/Sources/SwiftUIExtension/Extensions/ViewExtension.swift @@ -5,30 +5,6 @@ extension View { public func onReceive(notification name: Notification.Name, perform action: @escaping (NotificationCenter.Publisher.Output) -> Void) -> some View { self.onReceive(NotificationCenter.default.publisher(for: name), perform: action) } - - public func containerBackgroundForWidget(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View { - modifier(ContainerBackgroundForWidgetModifier(background: background)) - } -} - -struct ContainerBackgroundForWidgetModifier: ViewModifier where Background: View { - - let background: () -> Background - - func body(content: Content) -> some View { - if #available(iOS 17.0, iOSApplicationExtension 17.0, watchOS 10.0, watchOSApplicationExtension 10.0, macOS 14.0, *) { - content - .containerBackground(for: .widget) { - background() - } - } else { - ZStack { - background() - content - .padding() - } - } - } } // MARK: - Only iOS