Fixes long activity names in circular widget

release
Laurent 3 years ago
parent 2d407b8abe
commit 9bf66adf33
  1. 49
      LaunchWidget/SingleTimerView.swift
  2. 2
      LeCountdown/Views/Countdown/CountdownDialView.swift

@ -56,19 +56,35 @@ struct LockScreenCountdownView: View {
var body: some View { var body: some View {
VStack { VStack {
Text(timer.displayName.uppercased()) Text(activityName.uppercased())
if let countdown = timer as? Countdown { if let countdown = self.timer as? Countdown {
Text(countdown.duration.minuteSecond) Text(countdown.duration.minuteSecond)
.monospaced()
} }
} }
.monospaced() .multilineTextAlignment(.center)
.foregroundColor(Color.white) .foregroundColor(Color.white)
.font(self.font) .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 { private var font: Font {
switch family { switch self.family {
case .systemSmall, .systemMedium, .systemLarge, .systemExtraLarge: case .systemSmall, .systemMedium, .systemLarge, .systemExtraLarge:
return .body return .body
case .accessoryCircular: case .accessoryCircular:
@ -93,16 +109,16 @@ struct MultiCountdownView: View {
var body: some View { var body: some View {
if timers.isEmpty { if self.timers.isEmpty {
VoidView() VoidView()
} else { } else {
LazyVGrid( LazyVGrid(
columns: columns, columns: self.columns,
spacing: 10.0 spacing: 10.0
) { ) {
ForEach(timers) { timer in ForEach(self.timers) { timer in
Link(destination: timer.url) { Link(destination: timer.url) {
HStack { HStack {
@ -127,23 +143,6 @@ struct MultiCountdownView: View {
} }
}.padding() }.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)
} }
} }

@ -17,7 +17,7 @@ struct CountdownDialView: View {
HStack { HStack {
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(countdown.activity?.name?.uppercased() ?? "") Text(countdown.activity?.name?.uppercased() ?? "").multilineTextAlignment(.leading)
Text(countdown.duration.minuteSecond) Text(countdown.duration.minuteSecond)
} }
Spacer() Spacer()

Loading…
Cancel
Save