Fix widgets not working since iOS 17 #1234

This commit is contained in:
Marcus Kida 2024-02-20 16:34:40 +01:00 committed by Nathan Mattes
parent c05169affb
commit a5f74b8b8c
10 changed files with 40 additions and 1 deletions

View File

@ -45,6 +45,7 @@
2A728134297EA9D8004138C5 /* WidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2A728120297EA9D7004138C5 /* WidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2A72813F297EC762004138C5 /* WidgetExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A72813E297EC762004138C5 /* WidgetExtension.swift */; };
2A82294F29262EE000D2A1F7 /* AppContext+NextAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A82294E29262EE000D2A1F7 /* AppContext+NextAccount.swift */; };
2A84443C2B84F68100071C5B /* View+WidgetBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A84443B2B84F68100071C5B /* View+WidgetBackground.swift */; };
2A86A14629892944007F1062 /* MultiFollowersCountIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A86A14529892944007F1062 /* MultiFollowersCountIntentHandler.swift */; };
2A86A14929892B3A007F1062 /* MultiFollowersCountWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A86A14829892B3A007F1062 /* MultiFollowersCountWidget.swift */; };
2A86A14B2989326E007F1062 /* MultiFollowersCountWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A86A14A2989326E007F1062 /* MultiFollowersCountWidgetView.swift */; };
@ -661,6 +662,7 @@
2A72812F297EA9D8004138C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2A72813E297EC762004138C5 /* WidgetExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetExtension.swift; sourceTree = "<group>"; };
2A82294E29262EE000D2A1F7 /* AppContext+NextAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppContext+NextAccount.swift"; sourceTree = "<group>"; };
2A84443B2B84F68100071C5B /* View+WidgetBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+WidgetBackground.swift"; sourceTree = "<group>"; };
2A86A14529892944007F1062 /* MultiFollowersCountIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFollowersCountIntentHandler.swift; sourceTree = "<group>"; };
2A86A14829892B3A007F1062 /* MultiFollowersCountWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFollowersCountWidget.swift; sourceTree = "<group>"; };
2A86A14A2989326E007F1062 /* MultiFollowersCountWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFollowersCountWidgetView.swift; sourceTree = "<group>"; };
@ -1501,6 +1503,7 @@
2AE202A9297FDDF500F66E55 /* WidgetExtension.entitlements */,
2A72813E297EC762004138C5 /* WidgetExtension.swift */,
2A728126297EA9D7004138C5 /* WidgetExtensionBundle.swift */,
2A84443B2B84F68100071C5B /* View+WidgetBackground.swift */,
2AB50120299243FB00346092 /* WidgetExtension.intentdefinition */,
2A72812D297EA9D8004138C5 /* Assets.xcassets */,
2A72812F297EA9D8004138C5 /* Info.plist */,
@ -3593,6 +3596,7 @@
2AB5011E299243FB00346092 /* WidgetExtension.intentdefinition in Sources */,
2A86A14B2989326E007F1062 /* MultiFollowersCountWidgetView.swift in Sources */,
2A72813F297EC762004138C5 /* WidgetExtension.swift in Sources */,
2A84443C2B84F68100071C5B /* View+WidgetBackground.swift in Sources */,
2A86A14929892B3A007F1062 /* MultiFollowersCountWidget.swift in Sources */,
2A33AB662982C4AF008A7FB1 /* FollowersCountWidgetView.swift in Sources */,
2A9D0664298C048800BF38CB /* LatestFollowersWidget.swift in Sources */,

View File

@ -65,6 +65,7 @@ struct FollowersCountWidget: Widget {
.configurationDisplayName(L10n.Widget.FollowersCount.configurationDisplayName)
.description(L10n.Widget.FollowersCount.configurationDescription)
.supportedFamilies(availableFamilies)
.contentMarginsDisabled() // Disable excessive margins (only effective for iOS >= 17.0
}
}

View File

@ -34,6 +34,7 @@ struct FollowersCountWidgetView: View {
.multilineTextAlignment(.center)
.font(.caption)
.padding(.all, 20)
.emptyWidgetBackground()
}
}
@ -66,6 +67,7 @@ struct FollowersCountWidgetView: View {
.padding(.vertical, 16)
Spacer()
}
.emptyWidgetBackground()
}
private func viewForSmallWidgetYesChart(_ account: FollowersEntryAccountable) -> some View {
@ -125,6 +127,7 @@ struct FollowersCountWidgetView: View {
}
}
.padding(.top, 16)
.emptyWidgetBackground()
}
private func viewForAccessoryRectangular(_ account: FollowersEntryAccountable) -> some View {
@ -144,11 +147,11 @@ struct FollowersCountWidgetView: View {
}
Spacer()
}
.emptyWidgetBackground()
}
private func viewForAccessoryCircular(_ account :FollowersEntryAccountable) -> some View {
ZStack {
AccessoryWidgetBackground()
VStack {
Image("BrandIcon")
@ -158,5 +161,6 @@ struct FollowersCountWidgetView: View {
.truncationMode(.tail)
}
}
.widgetBackground(AccessoryWidgetBackground())
}
}

View File

@ -159,6 +159,7 @@ struct HashtagWidget: Widget {
.configurationDisplayName(L10n.Widget.Hashtag.Configuration.displayName)
.description(L10n.Widget.Hashtag.Configuration.description)
.supportedFamilies(availableFamilies)
.contentMarginsDisabled() // Disable excessive margins (only effective for iOS >= 17.0
}
}

View File

@ -65,6 +65,7 @@ struct HashtagWidgetView: View {
}
}
.padding(EdgeInsets(top: 12, leading: 29, bottom: 12, trailing: 29))
.emptyWidgetBackground()
}
private func viewForRectangularAccessory() -> some View {
@ -86,6 +87,7 @@ struct HashtagWidgetView: View {
Text(statusWithColorHashtags: entry.hashtag.content, fontSize: 11, fontWeight: .medium)
.lineLimit(3)
}
.emptyWidgetBackground()
}
}

View File

@ -72,6 +72,7 @@ struct LatestFollowersWidget: Widget {
.configurationDisplayName(L10n.Widget.LatestFollowers.configurationDisplayName)
.description(L10n.Widget.LatestFollowers.configurationDescription)
.supportedFamilies(availableFamilies)
.contentMarginsDisabled() // Disable excessive margins (only effective for iOS >= 17.0
}
}

View File

@ -34,6 +34,7 @@ struct LatestFollowersWidgetView: View {
.multilineTextAlignment(.center)
.font(.caption)
.padding(.all, 20)
.emptyWidgetBackground()
}
}
@ -72,6 +73,7 @@ struct LatestFollowersWidgetView: View {
}
.padding(.horizontal, 20)
.padding(.vertical, 16)
.emptyWidgetBackground()
}
private func viewForMediumWidget(_ accounts: [LatestFollowersEntryAccountable], lastUpdate: Date) -> some View {
@ -119,6 +121,7 @@ struct LatestFollowersWidgetView: View {
}
.padding(.horizontal, 20)
.padding(.vertical, 16)
.emptyWidgetBackground()
}
}

View File

@ -65,6 +65,7 @@ struct MultiFollowersCountWidget: Widget {
.configurationDisplayName(L10n.Widget.MultipleFollowers.configurationDisplayName)
.description(L10n.Widget.MultipleFollowers.configurationDescription)
.supportedFamilies(availableFamilies)
.contentMarginsDisabled() // Disable excessive margins (only effective for iOS >= 17.0
}
}

View File

@ -25,6 +25,7 @@ struct MultiFollowersCountWidgetView: View {
.multilineTextAlignment(.center)
.font(.caption)
.padding(.all, 20)
.emptyWidgetBackground()
}
}
@ -55,6 +56,7 @@ struct MultiFollowersCountWidgetView: View {
Spacer()
}
.padding(.vertical, 16)
.emptyWidgetBackground()
}
private func viewForMediumWidget(_ accounts: [MultiFollowersEntryAccountable]) -> some View {
@ -89,5 +91,6 @@ struct MultiFollowersCountWidgetView: View {
Spacer()
}
.padding(.vertical, 16)
.emptyWidgetBackground()
}
}

View File

@ -0,0 +1,19 @@
// Copyright © 2024 Mastodon gGmbH. All rights reserved.
import SwiftUI
extension View {
func emptyWidgetBackground() -> some View {
widgetBackground(EmptyView())
}
func widgetBackground(_ backgroundView: some View) -> some View {
if #available(iOSApplicationExtension 17.0, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}