From 3e69ef40f1f0585adf8e41c4fd0cc440698ef5c4 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 17 Feb 2023 10:16:00 +0100 Subject: [PATCH] Minor improvements in widgets --- LaunchWidget/DefaultView.swift | 38 +++++++++++++++++++++++ LaunchWidget/LaunchWidget.swift | 44 +++++++++++++-------------- LaunchWidget/SingleTimerView.swift | 2 +- LeCountdown.xcodeproj/project.pbxproj | 4 +++ 4 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 LaunchWidget/DefaultView.swift diff --git a/LaunchWidget/DefaultView.swift b/LaunchWidget/DefaultView.swift new file mode 100644 index 0000000..1a8b092 --- /dev/null +++ b/LaunchWidget/DefaultView.swift @@ -0,0 +1,38 @@ +// +// DefaultView.swift +// LeCountdown +// +// Created by Laurent Morvillier on 17/02/2023. +// + +import SwiftUI +import WidgetKit + +struct DefaultView: View { + + @Environment(\.widgetFamily) var family: WidgetFamily + + var body: some View { + + switch family { + case .accessoryCorner, .accessoryCircular, .accessoryRectangular, .accessoryInline: + VStack { + Text("Configure me!").monospaced() + } + default: + VStack { + Text("Configure me!\n") + Text("Tea".uppercased()).monospaced() + Text("4:00").monospaced() + } + } + + } + +} + +struct DefaultView_Previews: PreviewProvider { + static var previews: some View { + DefaultView().previewContext(WidgetPreviewContext(family: .systemSmall)) + } +} diff --git a/LaunchWidget/LaunchWidget.swift b/LaunchWidget/LaunchWidget.swift index 643adcb..292d050 100644 --- a/LaunchWidget/LaunchWidget.swift +++ b/LaunchWidget/LaunchWidget.swift @@ -10,6 +10,7 @@ import SwiftUI import Intents struct Provider: IntentTimelineProvider { + func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(timers: [], date: Date(), configuration: SelectTimerIntent()) } @@ -74,15 +75,6 @@ struct CountdownMultiWidgetView: View { } -struct VoidView : View { - var body: some View { - VStack { - Text("Tea!") - Text("4:00") - } - } -} - struct LaunchWidgetEntryView : View { @Environment(\.widgetFamily) var family: WidgetFamily @@ -97,25 +89,29 @@ struct LaunchWidgetEntryView : View { CountdownSimpleWidgetView(timer: timer) .background(Image(timer.imageName)) } else { - VoidView() + DefaultView() } case .accessoryCircular: - if let countdown = entry.timers.first { - LockScreenCountdownView(timer: countdown) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(Color.black) - } else { - VoidView() + Group { + if let countdown = entry.timers.first { + LockScreenCountdownView(timer: countdown) + } else { + DefaultView() + } } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.white.opacity(0.1)) case .accessoryRectangular: - if let timer = entry.timers.first { - LockScreenCountdownView(timer: timer) - .frame(maxWidth: .infinity, maxHeight: .infinity) - .background(Color.black) - .cornerRadius(16.0) - } else { - VoidView() + Group { + if let timer = entry.timers.first { + LockScreenCountdownView(timer: timer) + } else { + DefaultView() + } } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.white.opacity(0.1)) + .cornerRadius(16.0) default: MultiCountdownView(timers: entry.timers) } @@ -147,6 +143,8 @@ struct LaunchWidget_Previews: PreviewProvider { .previewContext(WidgetPreviewContext(family: .systemSmall)) LaunchWidgetEntryView(entry: SimpleEntry(timers: [fake, fake, fake, fake], date: Date(), configuration: SelectTimerIntent())) .previewContext(WidgetPreviewContext(family: .systemMedium)) + LaunchWidgetEntryView(entry: SimpleEntry(timers: [fake], date: Date(), configuration: SelectTimerIntent())) + .previewContext(WidgetPreviewContext(family: .accessoryCircular)) LaunchWidgetEntryView(entry: SimpleEntry(timers: [fake], date: Date(), configuration: SelectTimerIntent())) .previewContext(WidgetPreviewContext(family: .accessoryRectangular)) diff --git a/LaunchWidget/SingleTimerView.swift b/LaunchWidget/SingleTimerView.swift index 0d0f9b5..acd02ae 100644 --- a/LaunchWidget/SingleTimerView.swift +++ b/LaunchWidget/SingleTimerView.swift @@ -111,7 +111,7 @@ struct MultiCountdownView: View { var body: some View { if self.timers.isEmpty { - VoidView() + DefaultView() } else { LazyVGrid( diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index 8e152be..0629ba6 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -110,6 +110,7 @@ C4BA2B25299D35C100CB4FBA /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B24299D35C100CB4FBA /* HomeView.swift */; }; C4BA2B2D299E2DEE00CB4FBA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B2C299E2DEE00CB4FBA /* Preferences.swift */; }; C4BA2B2F299E69A000CB4FBA /* View+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B2E299E69A000CB4FBA /* View+Extension.swift */; }; + C4BA2B32299F75DE00CB4FBA /* DefaultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B30299F759700CB4FBA /* DefaultView.swift */; }; C4F8B1532987FE6F005C86A5 /* LaunchWidgetLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */; }; C4F8B15729891271005C86A5 /* Conductor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B15629891271005C86A5 /* Conductor.swift */; }; C4F8B15929891528005C86A5 /* forest_stream.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C4F8B15829891528005C86A5 /* forest_stream.mp3 */; }; @@ -293,6 +294,7 @@ C4BA2B24299D35C100CB4FBA /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; C4BA2B2C299E2DEE00CB4FBA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; C4BA2B2E299E69A000CB4FBA /* View+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extension.swift"; sourceTree = ""; }; + C4BA2B30299F759700CB4FBA /* DefaultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultView.swift; sourceTree = ""; }; C4F8B15629891271005C86A5 /* Conductor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conductor.swift; sourceTree = ""; }; C4F8B15829891528005C86A5 /* forest_stream.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = forest_stream.mp3; sourceTree = ""; }; C4F8B15E298961A7005C86A5 /* ReorderableForEach.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableForEach.swift; sourceTree = ""; }; @@ -453,6 +455,7 @@ C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */, C438C7D92981216200BF3EF9 /* LaunchWidget.swift */, C438C7E92981260D00BF3EF9 /* SingleTimerView.swift */, + C4BA2B30299F759700CB4FBA /* DefaultView.swift */, C438C7DB2981216200BF3EF9 /* LaunchWidget.intentdefinition */, C438C7DC2981216300BF3EF9 /* Assets.xcassets */, C438C7DE2981216300BF3EF9 /* Info.plist */, @@ -954,6 +957,7 @@ C4BA2B18299BE6A000CB4FBA /* Interval+CoreDataClass.swift in Sources */, C4F8B18E298AC288005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */, C4F8B1AE298AC451005C86A5 /* Alarm+CoreDataProperties.swift in Sources */, + C4BA2B32299F75DE00CB4FBA /* DefaultView.swift in Sources */, C4F8B18D298AC288005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */, C4BA2B14299BE6A000CB4FBA /* IntervalGroup+CoreDataProperties.swift in Sources */, C438C8182982BFC100BF3EF9 /* Persistence.swift in Sources */,