From aa6e0179cbf19101d5f5a0f8bf9c84a784b0c9bb Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Tue, 3 Oct 2023 15:09:04 +0300 Subject: [PATCH 01/12] Disable additional iOS17 margins for widgets --- .../LockScreenWidgets/LockScreenStatsWidget.swift | 1 + WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift | 1 + WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift | 1 + WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift | 1 + 4 files changed, 4 insertions(+) diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift index 6eac12ea4154..250c6be16b0f 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift @@ -36,5 +36,6 @@ struct LockScreenStatsWidget: Widget { .configurationDisplayName(config.displayName) .description(config.description) .supportedFamilies(config.supportFamilies) + .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift index 5d6d5c071f0a..64eac09c8ed1 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift @@ -33,5 +33,6 @@ struct HomeWidgetAllTime: Widget { .configurationDisplayName(LocalizableStrings.allTimeWidgetTitle) .description(LocalizableStrings.allTimePreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) + .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift index 9d419523fefc..d0b7508a4673 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift @@ -53,5 +53,6 @@ struct HomeWidgetThisWeek: Widget { .configurationDisplayName(LocalizableStrings.thisWeekWidgetTitle) .description(LocalizableStrings.thisWeekPreviewDescription) .supportedFamilies([.systemMedium, .systemLarge]) + .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift index e4637d5aee09..4d48f171c2f2 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift @@ -34,5 +34,6 @@ struct HomeWidgetToday: Widget { .configurationDisplayName(LocalizableStrings.todayWidgetTitle) .description(LocalizableStrings.todayPreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) + .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets } } From dfaf4e82484e60c99f46f35cac717c6fb34afbc0 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 9 Oct 2023 17:54:18 +0300 Subject: [PATCH 02/12] Conform to iOS 17 removable background API on Lock Screen Widgets Conforming by implementing containerBackground API. For now, Lock Screen Widgets keep using AccessoryWidgetBackground(), since this background is not supported by removable background. --- .../Views/LockScreenMultiStatView.swift | 1 + .../Views/LockScreenSingleStatView.swift | 1 + .../Views/LockScreenUnconfiguredView.swift | 1 + .../Helpers/View+RemovableWidgetBackground.swift | 13 +++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 12 ++++++++++++ 5 files changed, 28 insertions(+) create mode 100644 WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift index cdb3f6869efb..16cee687edb2 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift @@ -31,6 +31,7 @@ struct LockScreenMultiStatView: View { Spacer() } } + .removableWidgetBackground() .accessibilityElement(children: .combine) } else { Text("Not implemented for widget family \(family.debugDescription)") diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift index d78d8f74339c..62f4315a2d3d 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift @@ -17,6 +17,7 @@ struct LockScreenSingleStatView: View { Spacer() } } + .removableWidgetBackground() .accessibilityElement(children: .combine) } else { Text("Not implemented for widget family \(family.debugDescription)") diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift index dd651b5cd16a..c668672a0910 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift @@ -14,6 +14,7 @@ struct LockScreenUnconfiguredView: View { .minimumScaleFactor(0.8) .multilineTextAlignment(.center) } + .removableWidgetBackground() } else { Text("Not implemented for widget family \(family.debugDescription)") } diff --git a/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift b/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift new file mode 100644 index 000000000000..648204ea0adf --- /dev/null +++ b/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift @@ -0,0 +1,13 @@ +import SwiftUI + +extension View { + func removableWidgetBackground(_ backgroundView: some View = EmptyView()) -> some View { + if #available(iOSApplicationExtension 17.0, *) { + return containerBackground(for: .widget) { + backgroundView + } + } else { + return background(backgroundView) + } + } +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 940fd0ff0774..c1ca60b8d70b 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -217,6 +217,7 @@ 01E2580B2ACDC72C00F09666 /* PlanWizardContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */; }; 01E2580C2ACDC72C00F09666 /* PlanWizardContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */; }; 01E2580E2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */; }; + 01E258092ACC3AA000F09666 /* View+RemovableWidgetBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */; }; 01E78D1D296EA54F00FB6863 /* StatsPeriodHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */; }; 02761EC02270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */; }; 02761EC222700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */; }; @@ -5876,6 +5877,7 @@ 01E258042ACC373800F09666 /* PlanWizardContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContent.swift; sourceTree = ""; }; 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModel.swift; sourceTree = ""; }; 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModelTests.swift; sourceTree = ""; }; + 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+RemovableWidgetBackground.swift"; sourceTree = ""; }; 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsPeriodHelperTests.swift; sourceTree = ""; }; 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlogDetailsViewController+SectionHelpers.swift"; sourceTree = ""; }; 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDetailsSubsectionToSectionCategoryTests.swift; sourceTree = ""; }; @@ -9870,6 +9872,14 @@ path = Plan; sourceTree = ""; }; + 01E258072ACC3A9000F09666 /* Helpers */ = { + isa = PBXGroup; + children = ( + 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */, + ); + path = Helpers; + sourceTree = ""; + }; 027AC51F2278982D0033E56E /* DomainCredit */ = { isa = PBXGroup; children = ( @@ -11520,6 +11530,7 @@ 3F526D2B2539F9D60069706C /* Views */ = { isa = PBXGroup; children = ( + 01E258072ACC3A9000F09666 /* Helpers */, 3FCF66E825CAF8C50047F337 /* ListStatsView.swift */, 3F5689FF25420DE80048A9E4 /* MultiStatsView.swift */, 3F5689EF254209790048A9E4 /* SingleStatView.swift */, @@ -20826,6 +20837,7 @@ 0107E0BA28F97D5000DE87DB /* TodayWidgetStats.swift in Sources */, C9B477AD29CC15D9008CBF49 /* WidgetDataReader.swift in Sources */, C9FE384129C2A3D200D39841 /* LockScreenTodayViewsStatWidgetConfig.swift in Sources */, + 01E258092ACC3AA000F09666 /* View+RemovableWidgetBackground.swift in Sources */, 0188FE402AA613850093EDA5 /* LockScreenMultiStatView.swift in Sources */, 0107E16128FFE99300DE87DB /* WidgetConfiguration.swift in Sources */, 0107E0BB28F97D5000DE87DB /* StatsWidgetsService.swift in Sources */, From 478e07522834653e1b031ab03073a12f233b171d Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 9 Oct 2023 17:58:23 +0300 Subject: [PATCH 03/12] Disable background removing for Home Screen widgets Home Screen widgets require layout adjustment to support background removal --- .../LockScreenWidgets/LockScreenStatsWidget.swift | 2 +- WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift | 3 ++- WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift | 3 ++- WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift index 250c6be16b0f..d28c62e62eb2 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift @@ -36,6 +36,6 @@ struct LockScreenStatsWidget: Widget { .configurationDisplayName(config.displayName) .description(config.description) .supportedFamilies(config.supportFamilies) - .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets + .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift index 64eac09c8ed1..e0124f4eeb46 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift @@ -33,6 +33,7 @@ struct HomeWidgetAllTime: Widget { .configurationDisplayName(LocalizableStrings.allTimeWidgetTitle) .description(LocalizableStrings.allTimePreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) - .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets + .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets + .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift index d0b7508a4673..80ca0d2a6f34 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift @@ -53,6 +53,7 @@ struct HomeWidgetThisWeek: Widget { .configurationDisplayName(LocalizableStrings.thisWeekWidgetTitle) .description(LocalizableStrings.thisWeekPreviewDescription) .supportedFamilies([.systemMedium, .systemLarge]) - .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets + .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets + .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift index 4d48f171c2f2..863862ee7627 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift @@ -34,6 +34,7 @@ struct HomeWidgetToday: Widget { .configurationDisplayName(LocalizableStrings.todayWidgetTitle) .description(LocalizableStrings.todayPreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) - .contentMarginsDisabled() /// Disabling additional iOS17 margins for widgets + .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets for StandBy + .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } From 5aab0b7fc71ad082ffc9c613372a509dcd8ff193 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Fri, 13 Oct 2023 16:38:54 +0300 Subject: [PATCH 04/12] Silence Xcode 14 warnings by wrapping new API calls in preprocessor macros --- .../LockScreenStatsWidget.swift | 2 +- .../View+RemovableWidgetBackground.swift | 13 -------- .../Views/Helpers/iOS17WidgetAPIs.swift | 32 +++++++++++++++++++ .../Widgets/HomeWidgetAllTime.swift | 4 +-- .../Widgets/HomeWidgetThisWeek.swift | 4 +-- .../Widgets/HomeWidgetToday.swift | 4 +-- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ++-- 7 files changed, 43 insertions(+), 22 deletions(-) delete mode 100644 WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift create mode 100644 WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift index d28c62e62eb2..96fddcb30cc1 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/LockScreenStatsWidget.swift @@ -36,6 +36,6 @@ struct LockScreenStatsWidget: Widget { .configurationDisplayName(config.displayName) .description(config.description) .supportedFamilies(config.supportFamilies) - .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets + .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets } } diff --git a/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift b/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift deleted file mode 100644 index 648204ea0adf..000000000000 --- a/WordPress/JetpackStatsWidgets/Views/Helpers/View+RemovableWidgetBackground.swift +++ /dev/null @@ -1,13 +0,0 @@ -import SwiftUI - -extension View { - func removableWidgetBackground(_ backgroundView: some View = EmptyView()) -> some View { - if #available(iOSApplicationExtension 17.0, *) { - return containerBackground(for: .widget) { - backgroundView - } - } else { - return background(backgroundView) - } - } -} diff --git a/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift new file mode 100644 index 000000000000..dec584ac62ea --- /dev/null +++ b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift @@ -0,0 +1,32 @@ +import SwiftUI + +extension View { + func removableWidgetBackground(_ backgroundView: some View = EmptyView()) -> some View { + if #available(iOSApplicationExtension 17.0, *) { + return containerBackground(for: .widget) { + backgroundView + } + } else { + return background(backgroundView) + } + } +} + +/// Silence warnings on Xcode 14 +extension WidgetConfiguration { + func iOS17ContentMarginsDisabled() -> some WidgetConfiguration { + if #available(iOSApplicationExtension 17.0, *) { + return contentMarginsDisabled() + } else { + return self + } + } + + func iOS17ContainerBackgroundRemovable(_ isRemovable: Bool = true) -> some WidgetConfiguration { + if #available(iOSApplicationExtension 17.0, *) { + return containerBackgroundRemovable(isRemovable) + } else { + return self + } + } +} diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift index e0124f4eeb46..def0426a71f9 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift @@ -33,7 +33,7 @@ struct HomeWidgetAllTime: Widget { .configurationDisplayName(LocalizableStrings.allTimeWidgetTitle) .description(LocalizableStrings.allTimePreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) - .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets - .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality + .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets + .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift index 80ca0d2a6f34..254eebf958c3 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift @@ -53,7 +53,7 @@ struct HomeWidgetThisWeek: Widget { .configurationDisplayName(LocalizableStrings.thisWeekWidgetTitle) .description(LocalizableStrings.thisWeekPreviewDescription) .supportedFamilies([.systemMedium, .systemLarge]) - .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets - .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality + .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets + .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift index 863862ee7627..46efe649cc18 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift @@ -34,7 +34,7 @@ struct HomeWidgetToday: Widget { .configurationDisplayName(LocalizableStrings.todayWidgetTitle) .description(LocalizableStrings.todayPreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) - .contentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets for StandBy - .containerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality + .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets for StandBy + .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index c1ca60b8d70b..4f15826831f9 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -218,6 +218,7 @@ 01E2580C2ACDC72C00F09666 /* PlanWizardContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */; }; 01E2580E2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */; }; 01E258092ACC3AA000F09666 /* View+RemovableWidgetBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */; }; + 01E258092ACC3AA000F09666 /* iOS17WidgetAPIs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */; }; 01E78D1D296EA54F00FB6863 /* StatsPeriodHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */; }; 02761EC02270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */; }; 02761EC222700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */; }; @@ -5878,6 +5879,7 @@ 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModel.swift; sourceTree = ""; }; 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModelTests.swift; sourceTree = ""; }; 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+RemovableWidgetBackground.swift"; sourceTree = ""; }; + 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOS17WidgetAPIs.swift; sourceTree = ""; }; 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsPeriodHelperTests.swift; sourceTree = ""; }; 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlogDetailsViewController+SectionHelpers.swift"; sourceTree = ""; }; 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDetailsSubsectionToSectionCategoryTests.swift; sourceTree = ""; }; @@ -9875,7 +9877,7 @@ 01E258072ACC3A9000F09666 /* Helpers */ = { isa = PBXGroup; children = ( - 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */, + 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */, ); path = Helpers; sourceTree = ""; @@ -20837,7 +20839,7 @@ 0107E0BA28F97D5000DE87DB /* TodayWidgetStats.swift in Sources */, C9B477AD29CC15D9008CBF49 /* WidgetDataReader.swift in Sources */, C9FE384129C2A3D200D39841 /* LockScreenTodayViewsStatWidgetConfig.swift in Sources */, - 01E258092ACC3AA000F09666 /* View+RemovableWidgetBackground.swift in Sources */, + 01E258092ACC3AA000F09666 /* iOS17WidgetAPIs.swift in Sources */, 0188FE402AA613850093EDA5 /* LockScreenMultiStatView.swift in Sources */, 0107E16128FFE99300DE87DB /* WidgetConfiguration.swift in Sources */, 0107E0BB28F97D5000DE87DB /* StatsWidgetsService.swift in Sources */, From 190578f3710a0892a842455fbc8dc899eaabd476 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Fri, 13 Oct 2023 17:35:59 +0300 Subject: [PATCH 05/12] Update iOS17WidgetAPIs.swift --- .../JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift index dec584ac62ea..66ba16cb4ccc 100644 --- a/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift +++ b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift @@ -1,4 +1,5 @@ import SwiftUI +import WidgetKit extension View { func removableWidgetBackground(_ backgroundView: some View = EmptyView()) -> some View { From 3356e3d5042efd29187eadcd9530c8dd42428466 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 23 Oct 2023 11:40:10 +0300 Subject: [PATCH 06/12] Remove iOS17ContainerBackgroundRemovable --- .../Views/Helpers/iOS17WidgetAPIs.swift | 9 --------- .../JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift | 1 - .../JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift | 1 - .../JetpackStatsWidgets/Widgets/HomeWidgetToday.swift | 1 - 4 files changed, 12 deletions(-) diff --git a/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift index 66ba16cb4ccc..01e4ea037c92 100644 --- a/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift +++ b/WordPress/JetpackStatsWidgets/Views/Helpers/iOS17WidgetAPIs.swift @@ -13,7 +13,6 @@ extension View { } } -/// Silence warnings on Xcode 14 extension WidgetConfiguration { func iOS17ContentMarginsDisabled() -> some WidgetConfiguration { if #available(iOSApplicationExtension 17.0, *) { @@ -22,12 +21,4 @@ extension WidgetConfiguration { return self } } - - func iOS17ContainerBackgroundRemovable(_ isRemovable: Bool = true) -> some WidgetConfiguration { - if #available(iOSApplicationExtension 17.0, *) { - return containerBackgroundRemovable(isRemovable) - } else { - return self - } - } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift index def0426a71f9..803508bfba41 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetAllTime.swift @@ -34,6 +34,5 @@ struct HomeWidgetAllTime: Widget { .description(LocalizableStrings.allTimePreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets - .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift index 254eebf958c3..b1cbe3594acd 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetThisWeek.swift @@ -54,6 +54,5 @@ struct HomeWidgetThisWeek: Widget { .description(LocalizableStrings.thisWeekPreviewDescription) .supportedFamilies([.systemMedium, .systemLarge]) .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets - .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } diff --git a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift index 46efe649cc18..617cae2a7d6f 100644 --- a/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift +++ b/WordPress/JetpackStatsWidgets/Widgets/HomeWidgetToday.swift @@ -35,6 +35,5 @@ struct HomeWidgetToday: Widget { .description(LocalizableStrings.todayPreviewDescription) .supportedFamilies([.systemSmall, .systemMedium]) .iOS17ContentMarginsDisabled() /// Temporarily disable additional iOS17 margins for widgets for StandBy - .iOS17ContainerBackgroundRemovable(false) /// Temporarily disable iOS 17 background removing functionality } } From 94fc8392bedfbb2de6345de8664346fff9dd7c7e Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Wed, 18 Oct 2023 10:41:24 +0300 Subject: [PATCH 07/12] Change Home Screen Small Widget design if it's displayed without background Small Home Screen Widget can be shown in iPad lock screen on horizontal orientation: - Change the order of title and value - Increase font size of value --- .../Views/Cards/StatsValueView.swift | 1 + .../Views/Cards/VerticalCard.swift | 40 +++++++++++++------ .../Views/SingleStatView.swift | 34 ++++++++++++++-- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/StatsValueView.swift b/WordPress/JetpackStatsWidgets/Views/Cards/StatsValueView.swift index 3436559bd445..324ced823334 100644 --- a/WordPress/JetpackStatsWidgets/Views/Cards/StatsValueView.swift +++ b/WordPress/JetpackStatsWidgets/Views/Cards/StatsValueView.swift @@ -30,5 +30,6 @@ struct StatsValueView: View { .fontWeight(fontWeight) .foregroundColor(foregroundColor) .lineLimit(lineLimit) + .minimumScaleFactor(0.5) } } diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/VerticalCard.swift b/WordPress/JetpackStatsWidgets/Views/Cards/VerticalCard.swift index afef33c3743a..b9fb75193e2f 100644 --- a/WordPress/JetpackStatsWidgets/Views/Cards/VerticalCard.swift +++ b/WordPress/JetpackStatsWidgets/Views/Cards/VerticalCard.swift @@ -6,6 +6,8 @@ struct VerticalCard: View { let value: Int let largeText: Bool + @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground: Bool + private var titleFont: Font { largeText ? Appearance.largeTextFont : Appearance.textFont } @@ -17,18 +19,31 @@ struct VerticalCard: View { var body: some View { VStack(alignment: .leading) { - Text(title) - .font(Appearance.titleFont) - .fontWeight(Appearance.titleFontWeight) - .foregroundColor(Appearance.titleColor) - .accessibility(hidden: true) - StatsValueView(value: value, - font: titleFont, - fontWeight: .regular, - foregroundColor: Appearance.textColor, - lineLimit: nil) - .accessibility(label: accessibilityLabel) - + if showsWidgetContainerBackground { + Text(title) + .font(Appearance.titleFont) + .fontWeight(Appearance.titleFontWeight) + .foregroundColor(Appearance.titleColor) + .accessibility(hidden: true) + StatsValueView(value: value, + font: titleFont, + fontWeight: .regular, + foregroundColor: Appearance.textColor, + lineLimit: nil) + .accessibility(label: accessibilityLabel) + } else { + StatsValueView(value: value, + font: Appearance.extraLargeTextFont, + fontWeight: .heavy, + foregroundColor: Appearance.textColor, + lineLimit: nil) + .accessibility(label: accessibilityLabel) + Text(title) + .font(Appearance.titleFont) + .fontWeight(Appearance.titleFontWeight) + .foregroundColor(Appearance.titleColor) + .accessibility(hidden: true) + } } } } @@ -43,6 +58,7 @@ extension VerticalCard { static let titleColor = Color(UIColor.primary) static let largeTextFont = Font.largeTitle + static let extraLargeTextFont = Font.system(size: 48, weight: .bold) static let textFont = Font.title static let textColor = Color(.label) } diff --git a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift index 580d755823b2..60ec38e47178 100644 --- a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift +++ b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift @@ -1,19 +1,47 @@ import SwiftUI +import WidgetKit struct SingleStatView: View { - let viewData: GroupedViewData + let title: String + let description: String + let valueTitle: String + let value: Int + + init(viewData: GroupedViewData) { + self.title = viewData.widgetTitle + self.description = viewData.siteName + self.valueTitle = viewData.upperLeftTitle + self.value = viewData.upperLeftValue + } + + init(title: String, description: String, valueTitle: String, value: Int) { + self.title = title + self.description = description + self.valueTitle = valueTitle + self.value = value + } var body: some View { HStack { VStack(alignment: .leading) { - FlexibleCard(axis: .vertical, title: viewData.widgetTitle, value: .description(viewData.siteName), lineLimit: 2) + FlexibleCard(axis: .vertical, title: title, value: .description(description), lineLimit: 2) Spacer() - VerticalCard(title: viewData.upperLeftTitle, value: viewData.upperLeftValue, largeText: true) + VerticalCard(title: valueTitle, value: value, largeText: true) } Spacer() } } } + +@available(iOS 16.0, *) +struct SingleStatView_Previews: PreviewProvider { + static var previews: some View { + SingleStatView(title: "My WordPress Site", description: "Today", valueTitle: "Views", value: 124909) + .previewContext( + WidgetPreviewContext(family: .systemSmall) + ) + } +} From bb41a626f53cf47a7414e27f00da41396fbe6d0d Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 23 Oct 2023 11:41:18 +0300 Subject: [PATCH 08/12] Set removableWidgetBackground for unimplemented text --- .../LockScreenWidgets/Views/LockScreenMultiStatView.swift | 1 + .../LockScreenWidgets/Views/LockScreenSingleStatView.swift | 1 + .../LockScreenWidgets/Views/LockScreenUnconfiguredView.swift | 1 + 3 files changed, 3 insertions(+) diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift index 16cee687edb2..2ddcc195588b 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenMultiStatView.swift @@ -35,6 +35,7 @@ struct LockScreenMultiStatView: View { .accessibilityElement(children: .combine) } else { Text("Not implemented for widget family \(family.debugDescription)") + .removableWidgetBackground() } } diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift index 62f4315a2d3d..c9b82721c27d 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenSingleStatView.swift @@ -21,6 +21,7 @@ struct LockScreenSingleStatView: View { .accessibilityElement(children: .combine) } else { Text("Not implemented for widget family \(family.debugDescription)") + .removableWidgetBackground() } } } diff --git a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift index c668672a0910..89f9310e5522 100644 --- a/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift +++ b/WordPress/JetpackStatsWidgets/LockScreenWidgets/Views/LockScreenUnconfiguredView.swift @@ -17,6 +17,7 @@ struct LockScreenUnconfiguredView: View { .removableWidgetBackground() } else { Text("Not implemented for widget family \(family.debugDescription)") + .removableWidgetBackground() } } } From a1d932fedb1bd2bfa05acb879e62244e01a914c3 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 23 Oct 2023 13:18:29 +0300 Subject: [PATCH 09/12] Update Home Screen widgets according to design requirements --- .../Views/Cards/LockScreenFlexibleCard.swift | 81 +++++++++++++++++++ .../Views/Cards/LockScreenVerticalCard.swift | 39 +++++++++ .../Views/ListStatsView.swift | 1 + .../Views/MultiStatsView.swift | 1 + .../Views/SingleStatView.swift | 26 ++++-- .../Views/StatsWidgetsView.swift | 1 - .../Views/UnconfiguredView.swift | 1 + WordPress/WordPress.xcodeproj/project.pbxproj | 14 +++- 8 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift create mode 100644 WordPress/JetpackStatsWidgets/Views/Cards/LockScreenVerticalCard.swift diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift new file mode 100644 index 000000000000..99c8f2de9e7e --- /dev/null +++ b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift @@ -0,0 +1,81 @@ +import SwiftUI + +/// A card with a title and a numeric or string value that can be either vertically or horizontally stacked shown on LockScreen without background +struct LockScreenFlexibleCard: View { + let axis: Axis + let title: LocalizedString + let value: Value + let lineLimit: Int + + init(axis: Axis, title: LocalizedString, value: Value, lineLimit: Int = 1) { + self.axis = axis + self.title = title + self.value = value + self.lineLimit = lineLimit + } + + enum Value { + case number(Int) + case description(String) + } + + @ViewBuilder + private var descriptionView: some View { + + switch value { + + case .number(let number): + + StatsValueView(value: number, + font: Appearance.textFont, + fontWeight: Appearance.textFontWeight, + foregroundColor: Appearance.textColor, + lineLimit: lineLimit) + + case .description(let description): + + Text(description) + .font(Appearance.textFont) + .fontWeight(Appearance.textFontWeight) + .foregroundColor(Appearance.textColor) + .lineLimit(lineLimit) + } + } + + private var titleView: some View { + Text(title) + .font(Appearance.titleFont) + .foregroundColor(Appearance.titleColor) + } + + var body: some View { + switch axis { + case .vertical: + VStack(alignment: .leading) { + descriptionView + titleView + } + + case .horizontal: + HStack { + descriptionView + Spacer() + titleView + } + } + } +} + +// MARK: - Appearance +extension LockScreenFlexibleCard { + + private enum Appearance { + static let textFont = Font.headline + static let textFontWeight = Font.Weight.semibold + static let textColor = Color(.label) + + static let titleFont = Font.subheadline + static let titleColor = Color(.secondaryLabel) + + } +} diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenVerticalCard.swift b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenVerticalCard.swift new file mode 100644 index 000000000000..752c31c24d84 --- /dev/null +++ b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenVerticalCard.swift @@ -0,0 +1,39 @@ +import SwiftUI + +/// A card with a title and a value stacked vertically shown on LockScreen without background +struct LockScreenVerticalCard: View { + let title: LocalizedString + let value: Int + + private var accessibilityLabel: Text { + // The colon makes VoiceOver pause between elements + Text(title) + Text(": ") + Text(value.abbreviatedString()) + } + + var body: some View { + VStack(alignment: .leading) { + StatsValueView(value: value, + font: Appearance.extraLargeTextFont, + fontWeight: .heavy, + foregroundColor: Appearance.textColor, + lineLimit: nil) + .accessibility(label: accessibilityLabel) + Text(title) + .font(Appearance.titleFont) + .fontWeight(Appearance.titleFontWeight) + .foregroundColor(Appearance.titleColor) + .accessibility(hidden: true) + } + } +} + +// MARK: - Appearance +extension LockScreenVerticalCard { + private enum Appearance { + static let titleFont = Font.headline + static let titleFontWeight = Font.Weight.semibold + static let titleColor = Color(UIColor.label) + static let extraLargeTextFont = Font.system(size: 48, weight: .bold) + static let textColor = Color(UIColor.label) + } +} diff --git a/WordPress/JetpackStatsWidgets/Views/ListStatsView.swift b/WordPress/JetpackStatsWidgets/Views/ListStatsView.swift index d96ecbde2e7c..62e5227bf636 100644 --- a/WordPress/JetpackStatsWidgets/Views/ListStatsView.swift +++ b/WordPress/JetpackStatsWidgets/Views/ListStatsView.swift @@ -33,6 +33,7 @@ struct ListStatsView: View { } } } + .removableWidgetBackground() } } diff --git a/WordPress/JetpackStatsWidgets/Views/MultiStatsView.swift b/WordPress/JetpackStatsWidgets/Views/MultiStatsView.swift index 86b86be89bdc..07dcb61ad517 100644 --- a/WordPress/JetpackStatsWidgets/Views/MultiStatsView.swift +++ b/WordPress/JetpackStatsWidgets/Views/MultiStatsView.swift @@ -23,6 +23,7 @@ Spacer() } } + .removableWidgetBackground() } /// Constructs a two-card column for the medium size Today widget diff --git a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift index 60ec38e47178..5fc855ebb580 100644 --- a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift +++ b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift @@ -2,12 +2,13 @@ import SwiftUI import WidgetKit struct SingleStatView: View { - let title: String let description: String let valueTitle: String let value: Int + @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground: Bool + init(viewData: GroupedViewData) { self.title = viewData.widgetTitle self.description = viewData.siteName @@ -25,21 +26,32 @@ struct SingleStatView: View { var body: some View { HStack { - VStack(alignment: .leading) { - FlexibleCard(axis: .vertical, title: title, value: .description(description), lineLimit: 2) - - Spacer() - VerticalCard(title: valueTitle, value: value, largeText: true) + if showsWidgetContainerBackground { + VStack(alignment: .leading) { + FlexibleCard(axis: .vertical, title: title, value: .description(description), lineLimit: 2) + Spacer() + VerticalCard(title: valueTitle, value: value, largeText: true) + } + .padding() + } else { + VStack(alignment: .leading) { + Spacer() + LockScreenFlexibleCard(axis: .vertical, title: title, value: .description(description), lineLimit: 2) + Spacer().frame(height: 4) + LockScreenVerticalCard(title: valueTitle, value: value) + Spacer() + } } Spacer() } + .removableWidgetBackground() } } @available(iOS 16.0, *) struct SingleStatView_Previews: PreviewProvider { static var previews: some View { - SingleStatView(title: "My WordPress Site", description: "Today", valueTitle: "Views", value: 124909) + SingleStatView(title: "Today", description: "My WordPress Site", valueTitle: "Views", value: 124909) .previewContext( WidgetPreviewContext(family: .systemSmall) ) diff --git a/WordPress/JetpackStatsWidgets/Views/StatsWidgetsView.swift b/WordPress/JetpackStatsWidgets/Views/StatsWidgetsView.swift index d7f16d5a46ed..5670d3a3d741 100644 --- a/WordPress/JetpackStatsWidgets/Views/StatsWidgetsView.swift +++ b/WordPress/JetpackStatsWidgets/Views/StatsWidgetsView.swift @@ -26,7 +26,6 @@ struct StatsWidgetsView: View { case .systemSmall: SingleStatView(viewData: viewData) .widgetURL(viewData.statsURL?.appendingSource(.homeScreenWidget)) - .padding() case .systemMedium: MultiStatsView(viewData: viewData) diff --git a/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift b/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift index f515edd8008b..9266e64fddc0 100644 --- a/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift +++ b/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift @@ -10,6 +10,7 @@ struct UnconfiguredView: View { .foregroundColor(Color(.secondaryLabel)) .multilineTextAlignment(.center) .padding() + .removableWidgetBackground() } var unconfiguredMessage: LocalizedString { diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 4f15826831f9..a296e7afd960 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -190,6 +190,8 @@ 0188FE4C2AA62F800093EDA5 /* LockScreenTodayLikesCommentsStatWidgetConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0188FE4A2AA62F800093EDA5 /* LockScreenTodayLikesCommentsStatWidgetConfig.swift */; }; 0189AF052ACAD89700F63393 /* ShoppingCartService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0189AF042ACAD89700F63393 /* ShoppingCartService.swift */; }; 0189AF062ACAD89700F63393 /* ShoppingCartService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0189AF042ACAD89700F63393 /* ShoppingCartService.swift */; }; + 018FF1352AE6771A00F301C3 /* LockScreenVerticalCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 018FF1342AE6771A00F301C3 /* LockScreenVerticalCard.swift */; }; + 018FF1372AE67C2600F301C3 /* LockScreenFlexibleCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 018FF1362AE67C2600F301C3 /* LockScreenFlexibleCard.swift */; }; 019D699E2A5EA963003B676D /* RootViewCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019D699D2A5EA963003B676D /* RootViewCoordinatorTests.swift */; }; 019D69A02A5EBF47003B676D /* WordPressAuthenticatorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019D699F2A5EBF47003B676D /* WordPressAuthenticatorProtocol.swift */; }; 019D69A12A5EBF47003B676D /* WordPressAuthenticatorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019D699F2A5EBF47003B676D /* WordPressAuthenticatorProtocol.swift */; }; @@ -214,11 +216,10 @@ 01E258032ACC36FA00F09666 /* PlanStep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258012ACC36FA00F09666 /* PlanStep.swift */; }; 01E258052ACC373800F09666 /* PlanWizardContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258042ACC373800F09666 /* PlanWizardContent.swift */; }; 01E258062ACC373800F09666 /* PlanWizardContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258042ACC373800F09666 /* PlanWizardContent.swift */; }; + 01E258092ACC3AA000F09666 /* iOS17WidgetAPIs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */; }; 01E2580B2ACDC72C00F09666 /* PlanWizardContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */; }; 01E2580C2ACDC72C00F09666 /* PlanWizardContentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */; }; 01E2580E2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */; }; - 01E258092ACC3AA000F09666 /* View+RemovableWidgetBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */; }; - 01E258092ACC3AA000F09666 /* iOS17WidgetAPIs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */; }; 01E78D1D296EA54F00FB6863 /* StatsPeriodHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */; }; 02761EC02270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */; }; 02761EC222700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */; }; @@ -5863,6 +5864,8 @@ 0188FE472AA62D080093EDA5 /* LockScreenMultiStatWidgetViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenMultiStatWidgetViewProvider.swift; sourceTree = ""; }; 0188FE4A2AA62F800093EDA5 /* LockScreenTodayLikesCommentsStatWidgetConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenTodayLikesCommentsStatWidgetConfig.swift; sourceTree = ""; }; 0189AF042ACAD89700F63393 /* ShoppingCartService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartService.swift; sourceTree = ""; }; + 018FF1342AE6771A00F301C3 /* LockScreenVerticalCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenVerticalCard.swift; sourceTree = ""; }; + 018FF1362AE67C2600F301C3 /* LockScreenFlexibleCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenFlexibleCard.swift; sourceTree = ""; }; 019D699D2A5EA963003B676D /* RootViewCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewCoordinatorTests.swift; sourceTree = ""; }; 019D699F2A5EBF47003B676D /* WordPressAuthenticatorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordPressAuthenticatorProtocol.swift; sourceTree = ""; }; 01A8508A2A8A126400BD8A97 /* support_chat_widget.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = support_chat_widget.css; sourceTree = ""; }; @@ -5876,10 +5879,9 @@ 01DBFD8629BDCBF200F3720F /* JetpackNativeConnectionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackNativeConnectionService.swift; sourceTree = ""; }; 01E258012ACC36FA00F09666 /* PlanStep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanStep.swift; sourceTree = ""; }; 01E258042ACC373800F09666 /* PlanWizardContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContent.swift; sourceTree = ""; }; + 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOS17WidgetAPIs.swift; sourceTree = ""; }; 01E2580A2ACDC72C00F09666 /* PlanWizardContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModel.swift; sourceTree = ""; }; 01E2580D2ACDC88100F09666 /* PlanWizardContentViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanWizardContentViewModelTests.swift; sourceTree = ""; }; - 01E258082ACC3AA000F09666 /* View+RemovableWidgetBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+RemovableWidgetBackground.swift"; sourceTree = ""; }; - 01E258082ACC3AA000F09666 /* iOS17WidgetAPIs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOS17WidgetAPIs.swift; sourceTree = ""; }; 01E78D1C296EA54F00FB6863 /* StatsPeriodHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsPeriodHelperTests.swift; sourceTree = ""; }; 02761EBF2270072F009BAF0F /* BlogDetailsViewController+SectionHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BlogDetailsViewController+SectionHelpers.swift"; sourceTree = ""; }; 02761EC122700A9C009BAF0F /* BlogDetailsSubsectionToSectionCategoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogDetailsSubsectionToSectionCategoryTests.swift; sourceTree = ""; }; @@ -11564,7 +11566,9 @@ 3FCF66FA25CAF8E00047F337 /* ListRow.swift */, 3F568A2E254216550048A9E4 /* FlexibleCard.swift */, 3F568A1E254213B60048A9E4 /* VerticalCard.swift */, + 018FF1342AE6771A00F301C3 /* LockScreenVerticalCard.swift */, 3FA59B99258289E30073772F /* StatsValueView.swift */, + 018FF1362AE67C2600F301C3 /* LockScreenFlexibleCard.swift */, ); path = Cards; sourceTree = ""; @@ -20844,6 +20848,7 @@ 0107E16128FFE99300DE87DB /* WidgetConfiguration.swift in Sources */, 0107E0BB28F97D5000DE87DB /* StatsWidgetsService.swift in Sources */, C9B477B729CD2EF7008CBF49 /* LockScreenUnconfiguredView.swift in Sources */, + 018FF1372AE67C2600F301C3 /* LockScreenFlexibleCard.swift in Sources */, 0107E0BC28F97D5000DE87DB /* StatsWidgetsView.swift in Sources */, 01D2FF6B2AA782720038E040 /* LockScreenAllTimePostsBestViewsStatWidgetConfig.swift in Sources */, 0107E0BD28F97D5000DE87DB /* AppLocalizedString.swift in Sources */, @@ -20888,6 +20893,7 @@ 01D2FF652AA77F790038E040 /* LockScreenTodayViewsVisitorsStatWidgetConfig.swift in Sources */, 0107E0D528F97D5000DE87DB /* HomeWidgetTodayData.swift in Sources */, 0107E0D628F97D5000DE87DB /* AllTimeWidgetStats.swift in Sources */, + 018FF1352AE6771A00F301C3 /* LockScreenVerticalCard.swift in Sources */, 0107E0D728F97D5000DE87DB /* Sites.intentdefinition in Sources */, 0107E0D828F97D5000DE87DB /* LocalizableStrings.swift in Sources */, C9FE383229C2053300D39841 /* LockScreenSingleStatView.swift in Sources */, From b02d1a3a083561073e7150fbeb95049ee5621d72 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 23 Oct 2023 13:34:11 +0300 Subject: [PATCH 10/12] Add icon to title view --- .../Views/Cards/LockScreenFlexibleCard.swift | 69 +++++-------------- .../Views/SingleStatView.swift | 2 +- 2 files changed, 18 insertions(+), 53 deletions(-) diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift index 99c8f2de9e7e..5f4b25c75e02 100644 --- a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift +++ b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift @@ -1,67 +1,32 @@ import SwiftUI -/// A card with a title and a numeric or string value that can be either vertically or horizontally stacked shown on LockScreen without background +/// A card with a title and a string value that is shown on LockScreen without background struct LockScreenFlexibleCard: View { - let axis: Axis let title: LocalizedString - let value: Value + let description: LocalizedString let lineLimit: Int - init(axis: Axis, title: LocalizedString, value: Value, lineLimit: Int = 1) { - self.axis = axis + init(title: LocalizedString, description: LocalizedString, lineLimit: Int = 1) { self.title = title - self.value = value + self.description = description self.lineLimit = lineLimit } - enum Value { - case number(Int) - case description(String) - } - - @ViewBuilder - private var descriptionView: some View { - - switch value { - - case .number(let number): - - StatsValueView(value: number, - font: Appearance.textFont, - fontWeight: Appearance.textFontWeight, - foregroundColor: Appearance.textColor, - lineLimit: lineLimit) - - case .description(let description): - - Text(description) - .font(Appearance.textFont) - .fontWeight(Appearance.textFontWeight) - .foregroundColor(Appearance.textColor) - .lineLimit(lineLimit) - } - } - - private var titleView: some View { - Text(title) - .font(Appearance.titleFont) - .foregroundColor(Appearance.titleColor) - } - var body: some View { - switch axis { - case .vertical: - VStack(alignment: .leading) { - descriptionView - titleView - } - - case .horizontal: - HStack { - descriptionView - Spacer() - titleView + VStack(alignment: .leading) { + HStack(alignment: .firstTextBaseline, spacing: 4) { + Image("icon-jetpack") + .resizable() + .frame(width: 14, height: 14) + Text(description) + .font(Appearance.textFont) + .fontWeight(Appearance.textFontWeight) + .foregroundColor(Appearance.textColor) + .lineLimit(lineLimit) } + Text(title) + .font(Appearance.titleFont) + .foregroundColor(Appearance.titleColor) } } } diff --git a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift index 5fc855ebb580..f606543d2121 100644 --- a/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift +++ b/WordPress/JetpackStatsWidgets/Views/SingleStatView.swift @@ -36,7 +36,7 @@ struct SingleStatView: View { } else { VStack(alignment: .leading) { Spacer() - LockScreenFlexibleCard(axis: .vertical, title: title, value: .description(description), lineLimit: 2) + LockScreenFlexibleCard(title: title, description: description, lineLimit: 2) Spacer().frame(height: 4) LockScreenVerticalCard(title: valueTitle, value: value) Spacer() From 7130ef27a875f14315b5561e46df292c6714fd73 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Mon, 23 Oct 2023 13:34:25 +0300 Subject: [PATCH 11/12] Update label color of unconfigured view --- WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift b/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift index 9266e64fddc0..9145b392d1be 100644 --- a/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift +++ b/WordPress/JetpackStatsWidgets/Views/UnconfiguredView.swift @@ -3,11 +3,12 @@ import SwiftUI struct UnconfiguredView: View { var timelineEntry: StatsWidgetEntry + @Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground: Bool var body: some View { Text(unconfiguredMessage) .font(.footnote) - .foregroundColor(Color(.secondaryLabel)) + .foregroundColor(showsWidgetContainerBackground ? Color(.secondaryLabel) : Color(.label)) .multilineTextAlignment(.center) .padding() .removableWidgetBackground() From ca4673e951483e0dc7cdec7be82f86eb53ecd7f5 Mon Sep 17 00:00:00 2001 From: Povilas Staskus Date: Fri, 5 Jan 2024 11:53:09 +0000 Subject: [PATCH 12/12] Code structure --- .../Views/Cards/LockScreenFlexibleCard.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift index 5f4b25c75e02..47a48ec05dcc 100644 --- a/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift +++ b/WordPress/JetpackStatsWidgets/Views/Cards/LockScreenFlexibleCard.swift @@ -33,7 +33,6 @@ struct LockScreenFlexibleCard: View { // MARK: - Appearance extension LockScreenFlexibleCard { - private enum Appearance { static let textFont = Font.headline static let textFontWeight = Font.Weight.semibold @@ -41,6 +40,5 @@ extension LockScreenFlexibleCard { static let titleFont = Font.subheadline static let titleColor = Color(.secondaryLabel) - } }