// // MomentLiveActivity.swift // Moment // // Created by Tom Misch on 22.07.26. // import ActivityKit import WidgetKit import SwiftUI struct MomentAttributes: 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 MomentLiveActivity: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: MomentAttributes.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: "http://www.apple.com")) .keylineTint(Color.red) } } } extension MomentAttributes { fileprivate static var preview: MomentAttributes { MomentAttributes(name: "World") } } extension MomentAttributes.ContentState { fileprivate static var smiley: MomentAttributes.ContentState { MomentAttributes.ContentState(emoji: "😀") } fileprivate static var starEyes: MomentAttributes.ContentState { MomentAttributes.ContentState(emoji: "🤩") } } #Preview("Notification", as: .content, using: MomentAttributes.preview) { MomentLiveActivity() } contentStates: { MomentAttributes.ContentState.smiley MomentAttributes.ContentState.starEyes }