mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
77 lines
2.4 KiB
Swift
77 lines
2.4 KiB
Swift
//
|
|
// WidgetsLiveActivity.swift
|
|
// Widgets
|
|
//
|
|
// Created by Garth Vander Houwen on 2/28/23.
|
|
//
|
|
|
|
import ActivityKit
|
|
import WidgetKit
|
|
import SwiftUI
|
|
|
|
struct WidgetsAttributes: ActivityAttributes {
|
|
public struct ContentState: Codable, Hashable {
|
|
// Dynamic stateful properties about your activity go here!
|
|
var value: Int
|
|
}
|
|
|
|
// Fixed non-changing properties about your activity go here!
|
|
var name: String
|
|
}
|
|
|
|
struct WidgetsLiveActivity: Widget {
|
|
var body: some WidgetConfiguration {
|
|
ActivityConfiguration(for: WidgetsAttributes.self) { context in
|
|
// Lock screen/banner UI goes here
|
|
VStack {
|
|
Text("Hello")
|
|
}
|
|
.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")
|
|
// more content
|
|
}
|
|
} compactLeading: {
|
|
Text("L")
|
|
} compactTrailing: {
|
|
Text("T")
|
|
} minimal: {
|
|
Text("Min")
|
|
}
|
|
.widgetURL(URL(string: "http://www.apple.com"))
|
|
.keylineTint(Color.red)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct WidgetsLiveActivity_Previews: PreviewProvider {
|
|
static let attributes = WidgetsAttributes(name: "Me")
|
|
static let contentState = WidgetsAttributes.ContentState(value: 3)
|
|
|
|
static var previews: some View {
|
|
attributes
|
|
.previewContext(contentState, viewKind: .dynamicIsland(.compact))
|
|
.previewDisplayName("Island Compact")
|
|
attributes
|
|
.previewContext(contentState, viewKind: .dynamicIsland(.expanded))
|
|
.previewDisplayName("Island Expanded")
|
|
attributes
|
|
.previewContext(contentState, viewKind: .dynamicIsland(.minimal))
|
|
.previewDisplayName("Minimal")
|
|
attributes
|
|
.previewContext(contentState, viewKind: .content)
|
|
.previewDisplayName("Notification")
|
|
}
|
|
}
|