Skip to content

Commit b6ea9bb

Browse files
committed
Restructed.
1 parent e98b133 commit b6ea9bb

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ extension View {
66
public func containerBackgroundForWidgetCompability<Background>(background: @escaping () -> Background) -> some View where Background: View {
77
modifier(ContainerBackgroundForWidgetCompabilityModifier(background: background))
88
}
9+
10+
public func containerBackgroundForWidget<Background>(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View {
11+
modifier(ContainerBackgroundForWidgetModifier(background: background))
12+
}
913
}
1014

1115
struct ContainerBackgroundForWidgetCompabilityModifier<Background>: ViewModifier where Background: View {
@@ -23,3 +27,23 @@ struct ContainerBackgroundForWidgetCompabilityModifier<Background>: ViewModifier
2327
}
2428
}
2529
}
30+
31+
struct ContainerBackgroundForWidgetModifier<Background>: ViewModifier where Background: View {
32+
33+
let background: () -> Background
34+
35+
func body(content: Content) -> some View {
36+
if #available(iOS 17.0, iOSApplicationExtension 17.0, watchOS 10.0, watchOSApplicationExtension 10.0, macOS 14.0, *) {
37+
content
38+
.containerBackground(for: .widget) {
39+
background()
40+
}
41+
} else {
42+
ZStack {
43+
background()
44+
content
45+
.padding()
46+
}
47+
}
48+
}
49+
}

Sources/SwiftUIExtension/Extensions/ViewExtension.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ extension View {
55
public func onReceive(notification name: Notification.Name, perform action: @escaping (NotificationCenter.Publisher.Output) -> Void) -> some View {
66
self.onReceive(NotificationCenter.default.publisher(for: name), perform: action)
77
}
8-
9-
public func containerBackgroundForWidget<Background>(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View {
10-
modifier(ContainerBackgroundForWidgetModifier(background: background))
11-
}
12-
}
13-
14-
struct ContainerBackgroundForWidgetModifier<Background>: ViewModifier where Background: View {
15-
16-
let background: () -> Background
17-
18-
func body(content: Content) -> some View {
19-
if #available(iOS 17.0, iOSApplicationExtension 17.0, watchOS 10.0, watchOSApplicationExtension 10.0, macOS 14.0, *) {
20-
content
21-
.containerBackground(for: .widget) {
22-
background()
23-
}
24-
} else {
25-
ZStack {
26-
background()
27-
content
28-
.padding()
29-
}
30-
}
31-
}
328
}
339

3410
// MARK: - Only iOS

0 commit comments

Comments
 (0)