You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/ios/AppWidget/AppWidgetLiveActivity.swift

88 lines
2.5 KiB
Swift

//
// AppWidgetLiveActivity.swift
// AppWidget
//
// Created by Cloud Solutions on 15/12/2025.
//
import ActivityKit
import WidgetKit
import SwiftUI
struct LiveActivitiesAppAttributes: ActivityAttributes, Identifiable {
public typealias LiveDeliveryData = ContentState // don't forget to add this line, otherwise, live activity will not display it.
public struct ContentState: Codable, Hashable { }
var id = UUID()
}
extension LiveActivitiesAppAttributes {
func prefixedKey(_ key: String) -> String {
return "\(id)_\(key)"
}
}
let sharedDefault = UserDefaults(suiteName: "group.alhabib.pateientApp")!
struct AppWidgetAttributes: 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 AppWidgetLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: LiveActivitiesAppAttributes.self) { context in
// Lock screen/banner UI goes here
VStack {
Text("Hello patient")
}
.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")
}
} compactLeading: {
Text("Leading")
} compactTrailing: {
Text("trailing")
} minimal: {
Text("minimal")
}
.widgetURL(URL(string: "http://www.apple.com"))
.keylineTint(Color.red)
}
}
}
extension AppWidgetAttributes {
fileprivate static var preview: AppWidgetAttributes {
AppWidgetAttributes(name: "World")
}
}
extension AppWidgetAttributes.ContentState {
fileprivate static var smiley: AppWidgetAttributes.ContentState {
AppWidgetAttributes.ContentState(emoji: "😀")
}
fileprivate static var starEyes: AppWidgetAttributes.ContentState {
AppWidgetAttributes.ContentState(emoji: "🤩")
}
}