wip
This commit is contained in:
80
iosApp/MyCrib/MyCribLiveActivity.swift
Normal file
80
iosApp/MyCrib/MyCribLiveActivity.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// MyCribLiveActivity.swift
|
||||
// MyCrib
|
||||
//
|
||||
// Created by Trey Tartt on 11/5/25.
|
||||
//
|
||||
|
||||
import ActivityKit
|
||||
import WidgetKit
|
||||
import SwiftUI
|
||||
|
||||
struct MyCribAttributes: 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 MyCribLiveActivity: Widget {
|
||||
var body: some WidgetConfiguration {
|
||||
ActivityConfiguration(for: MyCribAttributes.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 MyCribAttributes {
|
||||
fileprivate static var preview: MyCribAttributes {
|
||||
MyCribAttributes(name: "World")
|
||||
}
|
||||
}
|
||||
|
||||
extension MyCribAttributes.ContentState {
|
||||
fileprivate static var smiley: MyCribAttributes.ContentState {
|
||||
MyCribAttributes.ContentState(emoji: "😀")
|
||||
}
|
||||
|
||||
fileprivate static var starEyes: MyCribAttributes.ContentState {
|
||||
MyCribAttributes.ContentState(emoji: "🤩")
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("Notification", as: .content, using: MyCribAttributes.preview) {
|
||||
MyCribLiveActivity()
|
||||
} contentStates: {
|
||||
MyCribAttributes.ContentState.smiley
|
||||
MyCribAttributes.ContentState.starEyes
|
||||
}
|
||||
Reference in New Issue
Block a user