Fix lock screen widget

release
Laurent 3 years ago
parent ab4cda2bd2
commit f5067feb99
  1. 4
      LaunchWidget/LaunchWidget.swift
  2. 36
      LaunchWidget/SingleCountdownView.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)

@ -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))
}

Loading…
Cancel
Save