From f5067feb99147675a637443a905b83668a9cc676 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 1 Feb 2023 09:16:28 +0100 Subject: [PATCH] Fix lock screen widget --- LaunchWidget/LaunchWidget.swift | 4 +-- LaunchWidget/SingleCountdownView.swift | 36 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/LaunchWidget/LaunchWidget.swift b/LaunchWidget/LaunchWidget.swift index 89788de..ff34545 100644 --- a/LaunchWidget/LaunchWidget.swift +++ b/LaunchWidget/LaunchWidget.swift @@ -101,7 +101,7 @@ struct LaunchWidgetEntryView : View { } case .accessoryCircular: if let countdown = entry.countdowns.first { - CountdownSimpleWidgetView(countdown: countdown) + LockScreenCountdownView(countdown: countdown) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.black) } else { @@ -109,7 +109,7 @@ struct LaunchWidgetEntryView : View { } case .accessoryRectangular: if let countdown = entry.countdowns.first { - CountdownSimpleWidgetView(countdown: countdown) + LockScreenCountdownView(countdown: countdown) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.black) .cornerRadius(16.0) diff --git a/LaunchWidget/SingleCountdownView.swift b/LaunchWidget/SingleCountdownView.swift index bc424f0..ca6ca37 100644 --- a/LaunchWidget/SingleCountdownView.swift +++ b/LaunchWidget/SingleCountdownView.swift @@ -37,6 +37,39 @@ struct SingleCountdownView: View { switch family { case .systemSmall, .systemMedium, .systemLarge, .systemExtraLarge: return .body + case .accessoryCircular: + return .footnote + default: + return .body + } + } + +} + + +struct LockScreenCountdownView: View { + + @Environment(\.widgetFamily) var family: WidgetFamily + + var countdown: Countdown + + var body: some View { + VStack { + Text(countdown.displayName.uppercased()) + Text(countdown.duration.minuteSecond) + } + .monospaced() + .foregroundColor(Color.white) + .font(self.font) + .widgetURL(countdown.url) + } + + private var font: Font { + switch family { + case .systemSmall, .systemMedium, .systemLarge, .systemExtraLarge: + return .body + case .accessoryCircular: + return .footnote default: return .body } @@ -125,7 +158,8 @@ struct CountdownView_Previews: PreviewProvider { static var previews: some View { SingleCountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .systemSmall)).background(.black) - SingleCountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryRectangular)) + LockScreenCountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryRectangular)) + LockScreenCountdownView(countdown: Countdown.fake(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .accessoryCircular)) MultiCountdownView(countdowns: self.countdowns(context: PersistenceController.preview.container.viewContext)).previewContext(WidgetPreviewContext(family: .systemMedium)) }