feat: start of widgets

This commit is contained in:
2026-01-04 21:45:44 -05:00
Unverified
parent caf8af638a
commit 0967b113be
37 changed files with 606 additions and 3612 deletions

View File

@@ -0,0 +1,73 @@
import ActivityKit
import WidgetKit
import SwiftUI
struct WidgetAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
// Dynamic stateful properties about your activity go here!
var emoji: String
}
// Fixed non-changing properties about your activity go here!
var name: String
}
struct WidgetLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: WidgetAttributes.self) { context in
// Lock screen/banner UI goes here
VStack {
Text("Hello \(context.state.emoji)")
}
.activityBackgroundTint(Color.cyan)
.activitySystemActionForegroundColor(Color.black)
} dynamicIsland: { context in
DynamicIsland {
// Expanded UI goes here. Compose the expanded UI through
// various regions, like leading/trailing/center/bottom
DynamicIslandExpandedRegion(.leading) {
Text("Leading")
}
DynamicIslandExpandedRegion(.trailing) {
Text("Trailing")
}
DynamicIslandExpandedRegion(.bottom) {
Text("Bottom \(context.state.emoji)")
// more content
}
} compactLeading: {
Text("L")
} compactTrailing: {
Text("T \(context.state.emoji)")
} minimal: {
Text(context.state.emoji)
}
.widgetURL(URL(string: "https://www.expo.dev"))
.keylineTint(Color.red)
}
}
}
extension WidgetAttributes {
fileprivate static var preview: WidgetAttributes {
WidgetAttributes(name: "World")
}
}
extension WidgetAttributes.ContentState {
fileprivate static var smiley: WidgetAttributes.ContentState {
WidgetAttributes.ContentState(emoji: "😀")
}
fileprivate static var starEyes: WidgetAttributes.ContentState {
WidgetAttributes.ContentState(emoji: "🤩")
}
}
#Preview("Notification", as: .content, using: WidgetAttributes.preview) {
WidgetLiveActivity()
} contentStates: {
WidgetAttributes.ContentState.smiley
WidgetAttributes.ContentState.starEyes
}