From 76ef018638655286d648325c5395ab80d1445b7c Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 1 Sep 2023 13:40:01 -0500 Subject: [PATCH] [AltWidget] Replaces legacy PreviewProvider previews with #Preview macro --- AltWidget/Widgets/AppDetailWidget.swift | 61 +++++---------------- AltWidget/Widgets/LockScreenWidget.swift | 69 +++++++++--------------- 2 files changed, 38 insertions(+), 92 deletions(-) diff --git a/AltWidget/Widgets/AppDetailWidget.swift b/AltWidget/Widgets/AppDetailWidget.swift index bdfe81d4..1e2178a3 100644 --- a/AltWidget/Widgets/AppDetailWidget.swift +++ b/AltWidget/Widgets/AppDetailWidget.swift @@ -171,51 +171,18 @@ private extension AppDetailWidgetView } } -struct WidgetView_Previews: PreviewProvider { - static var previews: some View { - let shortRefreshedDate = Calendar.current.date(byAdding: .day, value: -2, to: Date()) ?? Date() - let shortExpirationDate = Calendar.current.date(byAdding: .day, value: 7, to: shortRefreshedDate) ?? Date() - let expiredExpirationDate = Calendar.current.date(byAdding: .day, value: -155, to: Date()) ?? Date() - - let longRefreshedDate = Calendar.current.date(byAdding: .day, value: -100, to: Date()) ?? Date() - let longExpirationDate = Calendar.current.date(byAdding: .day, value: 365, to: longRefreshedDate) ?? Date() - - let altstore = AppSnapshot(name: "AltStore", - bundleIdentifier: Bundle.Info.appbundleIdentifier, - expirationDate: shortExpirationDate, - refreshedDate: shortRefreshedDate, - tintColor: .altPrimary, - icon: UIImage(named: "AltStore")) - - let delta = AppSnapshot(name: "Delta", - bundleIdentifier: "com.rileytestut.Delta", - expirationDate: longExpirationDate, - refreshedDate: longRefreshedDate, - tintColor: .deltaPrimary, - icon: UIImage(named: "Delta")) - - let expiredDelta = AppSnapshot(name: "Delta", - bundleIdentifier: "com.rileytestut.Delta", - expirationDate: expiredExpirationDate, - refreshedDate: shortRefreshedDate, - tintColor: .deltaPrimary, - icon: UIImage(named: "Delta")) - - return Group { - AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [altstore])) - .previewContext(WidgetPreviewContext(family: .systemSmall)) - - AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [delta])) - .previewContext(WidgetPreviewContext(family: .systemSmall)) - - AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [expiredDelta])) - .previewContext(WidgetPreviewContext(family: .systemSmall)) - - AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [])) - .previewContext(WidgetPreviewContext(family: .systemSmall)) - - AppDetailWidgetView(entry: AppsEntry(date: Date(), apps: [], isPlaceholder: true)) - .previewContext(WidgetPreviewContext(family: .systemSmall)) - } - } +#Preview(as: .systemSmall) { + AppDetailWidget() +} timeline: { + let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7) + let (altstore, delta, clip, _, longDelta, _) = AppSnapshot.makePreviewSnapshots() + + AppsEntry(date: Date(), apps: [altstore]) + AppsEntry(date: Date(), apps: [delta]) + AppsEntry(date: Date(), apps: [longDelta]) + + AppsEntry(date: expiredDate, apps: [delta]) + + AppsEntry(date: Date(), apps: []) + AppsEntry(date: Date(), apps: [], isPlaceholder: true) } diff --git a/AltWidget/Widgets/LockScreenWidget.swift b/AltWidget/Widgets/LockScreenWidget.swift index 3496cf02..522ea037 100644 --- a/AltWidget/Widgets/LockScreenWidget.swift +++ b/AltWidget/Widgets/LockScreenWidget.swift @@ -134,49 +134,28 @@ private struct ComplicationView: View } } -@available(iOS 16, *) -struct ComplicationView_Previews: PreviewProvider { - static var previews: some View { - let shortRefreshedDate = Calendar.current.date(byAdding: .day, value: -2, to: Date()) ?? Date() - let shortExpirationDate = Calendar.current.date(byAdding: .day, value: 7, to: shortRefreshedDate) ?? Date() - - let longRefreshedDate = Calendar.current.date(byAdding: .day, value: -100, to: Date()) ?? Date() - let longExpirationDate = Calendar.current.date(byAdding: .day, value: 365, to: longRefreshedDate) ?? Date() - - let expiredDate = shortExpirationDate.addingTimeInterval(1 * 60 * 60 * 24) - - let weekAltstore = AppSnapshot(name: "AltStore", - bundleIdentifier: Bundle.Info.appbundleIdentifier, - expirationDate: shortExpirationDate, - refreshedDate: shortRefreshedDate, - tintColor: .altPrimary, - icon: UIImage(named: "AltStore")) - - let yearAltstore = AppSnapshot(name: "AltStore", - bundleIdentifier: Bundle.Info.appbundleIdentifier, - expirationDate: longExpirationDate, - refreshedDate: longRefreshedDate, - tintColor: .altPrimary, - icon: UIImage(named: "AltStore")) - - return Group { - ComplicationView(entry: AppsEntry(date: Date(), apps: [weekAltstore]), style: .icon) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - - ComplicationView(entry: AppsEntry(date: expiredDate, apps: [weekAltstore]), style: .icon) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - - ComplicationView(entry: AppsEntry(date: longRefreshedDate, apps: [yearAltstore]), style: .icon) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - - ComplicationView(entry: AppsEntry(date: Date(), apps: [weekAltstore]), style: .text) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - - ComplicationView(entry: AppsEntry(date: expiredDate, apps: [weekAltstore]), style: .text) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - - ComplicationView(entry: AppsEntry(date: longRefreshedDate, apps: [yearAltstore]), style: .text) - .previewContext(WidgetPreviewContext(family: .accessoryCircular)) - } - } +private let widgetFamily = if #available(iOS 16, *) { WidgetFamily.accessoryCircular } else { WidgetFamily.systemSmall } + +#Preview("Text", as: widgetFamily) { + TextLockScreenWidget() +} timeline: { + let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7) + let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots() + + AppsEntry(date: Date(), apps: [altstore]) + AppsEntry(date: Date(), apps: [longAltStore]) + + AppsEntry(date: expiredDate, apps: [altstore]) +} + +#Preview("Icon", as: widgetFamily) { + IconLockScreenWidget() +} timeline: { + let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7) + let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots() + + AppsEntry(date: Date(), apps: [altstore]) + AppsEntry(date: Date(), apps: [longAltStore]) + + AppsEntry(date: expiredDate, apps: [altstore]) }