From 9bf66adf33b27c903349c6605d00c9d0e121bcae Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 16 Feb 2023 16:23:35 +0100 Subject: [PATCH] Fixes long activity names in circular widget --- LaunchWidget/SingleTimerView.swift | 49 +++++++++---------- .../Views/Countdown/CountdownDialView.swift | 2 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/LaunchWidget/SingleTimerView.swift b/LaunchWidget/SingleTimerView.swift index fb136d6..a4ba590 100644 --- a/LaunchWidget/SingleTimerView.swift +++ b/LaunchWidget/SingleTimerView.swift @@ -56,19 +56,35 @@ struct LockScreenCountdownView: View { var body: some View { VStack { - Text(timer.displayName.uppercased()) - if let countdown = timer as? Countdown { + Text(activityName.uppercased()) + if let countdown = self.timer as? Countdown { Text(countdown.duration.minuteSecond) + .monospaced() } } - .monospaced() + .multilineTextAlignment(.center) .foregroundColor(Color.white) .font(self.font) - .widgetURL(timer.url) + .widgetURL(self.timer.url) + } + + private var activityName: String { + switch self.family { + case .accessoryCircular: + let reduced = self.timer.displayName + if reduced.contains(" ") { + let initials = reduced.components(separatedBy: " ").compactMap { $0.first }.map { String($0) } + return initials.joined(separator: "") + } else { + return String(reduced.prefix(5)) + } + default: + return self.timer.displayName + } } private var font: Font { - switch family { + switch self.family { case .systemSmall, .systemMedium, .systemLarge, .systemExtraLarge: return .body case .accessoryCircular: @@ -93,16 +109,16 @@ struct MultiCountdownView: View { var body: some View { - if timers.isEmpty { + if self.timers.isEmpty { VoidView() } else { LazyVGrid( - columns: columns, + columns: self.columns, spacing: 10.0 ) { - ForEach(timers) { timer in + ForEach(self.timers) { timer in Link(destination: timer.url) { HStack { @@ -127,23 +143,6 @@ struct MultiCountdownView: View { } }.padding() - - - -// HStack { -// ForEach(countdowns) { countdown in -// -// Link(destination: countdown.url) { -// VStack { -// Text(countdown.name ?? "") -// Text(countdown.duration.minuteSecond) -// } -// .font(self.font) -// .frame(maxWidth: .infinity, maxHeight: .infinity) -// } -// -// } -// }.frame(maxWidth: .infinity) } } diff --git a/LeCountdown/Views/Countdown/CountdownDialView.swift b/LeCountdown/Views/Countdown/CountdownDialView.swift index 2defdea..0d2892e 100644 --- a/LeCountdown/Views/Countdown/CountdownDialView.swift +++ b/LeCountdown/Views/Countdown/CountdownDialView.swift @@ -17,7 +17,7 @@ struct CountdownDialView: View { HStack { VStack(alignment: .leading) { - Text(countdown.activity?.name?.uppercased() ?? "") + Text(countdown.activity?.name?.uppercased() ?? "").multilineTextAlignment(.leading) Text(countdown.duration.minuteSecond) } Spacer()