[AltWidget] Replaces legacy PreviewProvider previews with #Preview macro

This commit is contained in:
Riley Testut
2023-09-01 13:40:01 -05:00
committed by Magesh K
parent 2aaa7761fc
commit 76ef018638
2 changed files with 38 additions and 92 deletions

View File

@@ -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()
#Preview(as: .systemSmall) {
AppDetailWidget()
} timeline: {
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
let (altstore, delta, clip, _, longDelta, _) = AppSnapshot.makePreviewSnapshots()
let longRefreshedDate = Calendar.current.date(byAdding: .day, value: -100, to: Date()) ?? Date()
let longExpirationDate = Calendar.current.date(byAdding: .day, value: 365, to: longRefreshedDate) ?? Date()
AppsEntry(date: Date(), apps: [altstore])
AppsEntry(date: Date(), apps: [delta])
AppsEntry(date: Date(), apps: [longDelta])
let altstore = AppSnapshot(name: "AltStore",
bundleIdentifier: Bundle.Info.appbundleIdentifier,
expirationDate: shortExpirationDate,
refreshedDate: shortRefreshedDate,
tintColor: .altPrimary,
icon: UIImage(named: "AltStore"))
AppsEntry(date: expiredDate, apps: [delta])
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))
}
}
AppsEntry(date: Date(), apps: [])
AppsEntry(date: Date(), apps: [], isPlaceholder: true)
}

View File

@@ -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()
private let widgetFamily = if #available(iOS 16, *) { WidgetFamily.accessoryCircular } else { WidgetFamily.systemSmall }
let longRefreshedDate = Calendar.current.date(byAdding: .day, value: -100, to: Date()) ?? Date()
let longExpirationDate = Calendar.current.date(byAdding: .day, value: 365, to: longRefreshedDate) ?? Date()
#Preview("Text", as: widgetFamily) {
TextLockScreenWidget()
} timeline: {
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
let expiredDate = shortExpirationDate.addingTimeInterval(1 * 60 * 60 * 24)
AppsEntry(date: Date(), apps: [altstore])
AppsEntry(date: Date(), apps: [longAltStore])
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))
}
}
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])
}