Removed boilerplated widget source code from the Attendi widget target.
This commit is contained in:
@@ -83,7 +83,6 @@
|
||||
Attendi/Catalogs/Localizable.xcstrings,
|
||||
Attendi/Sources/Bundle/AttendiWidgetBundle.swift,
|
||||
"Attendi/Sources/Extensions/Image+Symbols.swift",
|
||||
Attendi/Sources/Intents/AppIntent.swift,
|
||||
Attendi/Sources/Intents/DiscardRecordingIntent.swift,
|
||||
Attendi/Sources/Intents/ProcessRecordingIntent.swift,
|
||||
Attendi/Sources/Intents/ToggleRecordingIntent.swift,
|
||||
@@ -92,7 +91,6 @@
|
||||
Attendi/Sources/Views/RecordingLiveActivityView.swift,
|
||||
Attendi/Sources/Views/RecordingStateLabel.swift,
|
||||
Attendi/Sources/Views/RecordingTimerText.swift,
|
||||
Attendi/Sources/Widgets/AttendiWidget.swift,
|
||||
Attendi/Sources/Widgets/RecordingLiveActivity.swift,
|
||||
);
|
||||
target = 0296F7ED2FFAB1B600D2C5FC /* AttendiWidgetExtension */;
|
||||
|
||||
@@ -8,7 +8,6 @@ struct AttendiWidgetBundle: WidgetBundle {
|
||||
|
||||
/// The widgets and Live Activities the bundle exposes.
|
||||
var body: some Widget {
|
||||
AttendiWidget()
|
||||
RecordingLiveActivity()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import WidgetKit
|
||||
import AppIntents
|
||||
|
||||
/// The configuration intent of the ``AttendiWidget`` placeholder, as scaffolded by the Xcode widget template.
|
||||
struct ConfigurationAppIntent: WidgetConfigurationIntent {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
static var title: LocalizedStringResource { "Configuration" }
|
||||
static var description: IntentDescription { "This is an example widget." }
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// An example configurable parameter.
|
||||
@Parameter(title: "Favorite Emoji", default: "😃")
|
||||
var favoriteEmoji: String
|
||||
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
/// The timeline provider of the ``AttendiWidget`` placeholder, producing entries from the widget's configuration intent.
|
||||
struct Provider: AppIntentTimelineProvider {
|
||||
|
||||
/// Returns a generic entry the system shows while the widget loads.
|
||||
func placeholder(in context: Context) -> SimpleEntry {
|
||||
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
|
||||
}
|
||||
|
||||
/// Returns a single entry for the given configuration, shown in transient contexts like the widget gallery.
|
||||
func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
|
||||
SimpleEntry(date: Date(), configuration: configuration)
|
||||
}
|
||||
|
||||
/// Returns a timeline of five entries an hour apart, starting from the current date.
|
||||
func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> {
|
||||
var entries: [SimpleEntry] = []
|
||||
|
||||
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
|
||||
let currentDate = Date()
|
||||
for hourOffset in 0 ..< 5 {
|
||||
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
|
||||
let entry = SimpleEntry(date: entryDate, configuration: configuration)
|
||||
entries.append(entry)
|
||||
}
|
||||
|
||||
return Timeline(entries: entries, policy: .atEnd)
|
||||
}
|
||||
|
||||
// func relevances() async -> WidgetRelevances<ConfigurationAppIntent> {
|
||||
// // Generate a list containing the contexts this widget is relevant in.
|
||||
// }
|
||||
}
|
||||
|
||||
/// A timeline entry of the ``AttendiWidget`` placeholder.
|
||||
struct SimpleEntry: TimelineEntry {
|
||||
/// The instant the entry applies to.
|
||||
let date: Date
|
||||
/// The configuration of the widget at the time of the entry.
|
||||
let configuration: ConfigurationAppIntent
|
||||
}
|
||||
|
||||
/// The view rendering a timeline entry of the ``AttendiWidget`` placeholder: the entry's time and the configured emoji.
|
||||
struct AttendiWidgetEntryView : View {
|
||||
/// The timeline entry to render.
|
||||
var entry: Provider.Entry
|
||||
|
||||
var body: some View {
|
||||
Text("Time:")
|
||||
Text(entry.date, style: .time)
|
||||
|
||||
Text("Favorite Emoji:")
|
||||
Text(entry.configuration.favoriteEmoji)
|
||||
}
|
||||
}
|
||||
|
||||
/// The placeholder Home Screen widget scaffolded by the Xcode widget template, yet to be replaced by the app's own widget.
|
||||
struct AttendiWidget: Widget {
|
||||
/// The identifier of the widget's kind.
|
||||
let kind: String = "AttendiWidget"
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
AppIntentConfiguration(kind: kind, intent: ConfigurationAppIntent.self, provider: Provider()) { entry in
|
||||
AttendiWidgetEntryView(entry: entry)
|
||||
.containerBackground(.fill.tertiary, for: .widget)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ConfigurationAppIntent {
|
||||
fileprivate static var smiley: ConfigurationAppIntent {
|
||||
let intent = ConfigurationAppIntent()
|
||||
intent.favoriteEmoji = "😀"
|
||||
return intent
|
||||
}
|
||||
|
||||
fileprivate static var starEyes: ConfigurationAppIntent {
|
||||
let intent = ConfigurationAppIntent()
|
||||
intent.favoriteEmoji = "🤩"
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
#Preview(as: .systemSmall) {
|
||||
AttendiWidget()
|
||||
} timeline: {
|
||||
SimpleEntry(date: .now, configuration: .smiley)
|
||||
SimpleEntry(date: .now, configuration: .starEyes)
|
||||
}
|
||||
Reference in New Issue
Block a user