Skip to content

Commit

Permalink
Fix iOS 17 Widget background view modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhnx committed Oct 28, 2023
1 parent 283f78f commit 13e82e4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Clendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
A371156E25C51AEB00D65F59 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37F0B2425C5190000DFFC41 /* Color+Extensions.swift */; };
A371157B25C51B9000D65F59 /* View+Gradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A371157A25C51B9000D65F59 /* View+Gradient.swift */; };
A371157C25C51B9000D65F59 /* View+Gradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A371157A25C51B9000D65F59 /* View+Gradient.swift */; };
A3792E492AECA55C0059B3C8 /* WidgetView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3792E482AECA55C0059B3C8 /* WidgetView+Extensions.swift */; };
A3792E4A2AECA55C0059B3C8 /* WidgetView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3792E482AECA55C0059B3C8 /* WidgetView+Extensions.swift */; };
A37B3B6F22506FB000D0488B /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37B3B6E22506FB000D0488B /* Date+Extensions.swift */; };
A37D5F2327C4F96900495638 /* Shift in Frameworks */ = {isa = PBXBuildFile; productRef = A37D5F2227C4F96900495638 /* Shift */; };
A37F0AE425C4807500DFFC41 /* ClendarWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = A37F0AE725C4807500DFFC41 /* ClendarWidget.intentdefinition */; };
Expand Down Expand Up @@ -346,6 +348,7 @@
A368474C2554457B004BDCC6 /* Bundle+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Extensions.swift"; sourceTree = "<group>"; };
A36A504F2250EE6A00B12034 /* LoggerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerConfiguration.swift; sourceTree = "<group>"; };
A371157A25C51B9000D65F59 /* View+Gradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Gradient.swift"; sourceTree = "<group>"; };
A3792E482AECA55C0059B3C8 /* WidgetView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WidgetView+Extensions.swift"; sourceTree = "<group>"; };
A37B3B6E22506FB000D0488B /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = "<group>"; };
A37F0AE625C4807500DFFC41 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/ClendarWidget.intentdefinition; sourceTree = "<group>"; };
A37F0AF725C4807B00DFFC41 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/ClendarWidget.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -825,6 +828,7 @@
isa = PBXGroup;
children = (
A33F846525AF3404001324A0 /* WidgetBackgroundView.swift */,
A3792E482AECA55C0059B3C8 /* WidgetView+Extensions.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -1414,6 +1418,7 @@
A38A4D98254D73F400B35F98 /* Constants.swift in Sources */,
A3064D47254CF15500C7F228 /* WidgetEntry.swift in Sources */,
A3209BA7258CE315002470CF /* ViewModifiers.swift in Sources */,
A3792E4A2AECA55C0059B3C8 /* WidgetView+Extensions.swift in Sources */,
A3C23FE027C9FC1D004838E8 /* Color+Theme.swift in Sources */,
A38A4DCE254D752A00B35F98 /* WorkItem.swift in Sources */,
A38A4DAB254D742B00B35F98 /* UserDefaults+Extensions.swift in Sources */,
Expand Down Expand Up @@ -1474,6 +1479,7 @@
A30E48232541F4EF00B4B027 /* Utilities.swift in Sources */,
A315F9FB25CF04A800E909DB /* ModalWrapperView.swift in Sources */,
A367FBF3254DCA840059F6D7 /* SettingsConstants.swift in Sources */,
A3792E492AECA55C0059B3C8 /* WidgetView+Extensions.swift in Sources */,
A3C2400027CA108C004838E8 /* ClendarPlusView.swift in Sources */,
A3D6843725A9F467009C31D5 /* RatingManager.swift in Sources */,
A31AFDB725CE6E2A0092D44D /* PurchaseButtonStyle.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CalendarGridWidget: Widget {
) { entry in
CalendarGridWidgetView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(WidgetBackgroundView())
.widgetBackground(WidgetBackgroundView())
}
.configurationDisplayName(NSLocalizedString("Calendar grid view", comment: ""))
.description(NSLocalizedString("Month view calendar", comment: ""))
Expand Down
22 changes: 22 additions & 0 deletions ClendarWidget/Widget/Components/WidgetView+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// WidgetView+Extensions.swift
// Clendar
//
// Created by Vinh Nguyen on 28/10/2023.
// Copyright © 2023 Vinh Nguyen. All rights reserved.
//

import SwiftUI

// https://stackoverflow.com/a/76842922/1477298
extension View {
func widgetBackground(_ backgroundView: some View) -> some View {
if #available(iOS 17, macCatalyst 17, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}
2 changes: 1 addition & 1 deletion ClendarWidget/Widget/Date Info/DateInfoWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct DateInfoWidget: Widget {
provider: DateInfoWidgetTimelineProvider()) { entry in
DateInfoWidgetEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(WidgetBackgroundView())
.widgetBackground(WidgetBackgroundView())
}
.configurationDisplayName(NSLocalizedString("Date Info Widget", comment: ""))
.description(NSLocalizedString("Check calendar at a glance", comment: ""))
Expand Down
2 changes: 1 addition & 1 deletion ClendarWidget/Widget/Event List/EventListWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct EventListWidget: Widget {
provider: DateInfoWidgetTimelineProvider()) { entry in
EventsListWidgetView(entry: entry, minimizeContents: true)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(WidgetBackgroundView())
.widgetBackground(WidgetBackgroundView())
}
.configurationDisplayName(NSLocalizedString("Event List Widget", comment: ""))
.description(NSLocalizedString("Your day events at a glance", comment: ""))
Expand Down
2 changes: 1 addition & 1 deletion ClendarWidget/Widget/Lunar/LunarDateInfoWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct LunarDateInfoWidget: Widget {
) { entry in
LunarSmallDateWidgetView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(WidgetBackgroundView())
.widgetBackground(WidgetBackgroundView())
}
.configurationDisplayName(NSLocalizedString("Lunar Date", comment: ""))
.description(NSLocalizedString("Lunar calendar at a glance", comment: ""))
Expand Down

0 comments on commit 13e82e4

Please sign in to comment.