Skip to content

Commit

Permalink
Restructed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Sep 13, 2023
1 parent e98b133 commit b6ea9bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 24 additions & 0 deletions Sources/SwiftUIExtension/Compability/WidgetViewCompability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ extension View {
public func containerBackgroundForWidgetCompability<Background>(background: @escaping () -> Background) -> some View where Background: View {
modifier(ContainerBackgroundForWidgetCompabilityModifier(background: background))
}

public func containerBackgroundForWidget<Background>(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View {
modifier(ContainerBackgroundForWidgetModifier(background: background))
}
}

struct ContainerBackgroundForWidgetCompabilityModifier<Background>: ViewModifier where Background: View {
Expand All @@ -23,3 +27,23 @@ struct ContainerBackgroundForWidgetCompabilityModifier<Background>: ViewModifier
}
}
}

struct ContainerBackgroundForWidgetModifier<Background>: 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()
}
}
}
}
24 changes: 0 additions & 24 deletions Sources/SwiftUIExtension/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Background>(@ViewBuilder background: @escaping () -> Background) -> some View where Background: View {
modifier(ContainerBackgroundForWidgetModifier(background: background))
}
}

struct ContainerBackgroundForWidgetModifier<Background>: 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
Expand Down

0 comments on commit b6ea9bb

Please sign in to comment.