You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
//
|
|
// JustOneThingWidget.swift
|
|
// JustOneThing
|
|
//
|
|
// Created by Alan Francis on 11/06/2023.
|
|
//
|
|
|
|
import WidgetKit
|
|
import SwiftUI
|
|
import Intents
|
|
|
|
@main
|
|
struct JustOneThingWidgetBundle: WidgetBundle {
|
|
var body: some Widget {
|
|
JustOneThingWidget()
|
|
}
|
|
}
|
|
|
|
struct ThingView : View {
|
|
let thing: Thing
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
var body: some View {
|
|
Text(thing.text)
|
|
.fitSystemFont(lineLimit: 4)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundColor(.randomForegroundColor(colorScheme))
|
|
}
|
|
}
|
|
|
|
struct ThingEntryView : View {
|
|
var entry: ThingEntry
|
|
|
|
var body: some View {
|
|
ThingView(thing: entry.thing).padding()
|
|
}
|
|
}
|
|
|
|
struct JustOneThingWidget: Widget {
|
|
let kind: String = "JustOneThingWidget"
|
|
|
|
var body: some WidgetConfiguration {
|
|
IntentConfiguration(kind: kind,
|
|
intent: ConfigurationIntent.self,
|
|
provider: ThingProvider()) { entry in
|
|
ThingEntryView(entry: entry)
|
|
}
|
|
.configurationDisplayName("My Widget")
|
|
.description("This is an example widget.")
|
|
}
|
|
}
|
|
|
|
struct Widget_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ThingEntryView(entry: ThingEntry(thing: Thing(text: "dont forget toothepase", createdAt: Date())))
|
|
#if os(watchOS)
|
|
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
|
|
#else
|
|
.previewContext(WidgetPreviewContext(family: .systemMedium))
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|