-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathExampleWidgetLiveActivity.swift
More file actions
66 lines (64 loc) · 2.36 KB
/
ExampleWidgetLiveActivity.swift
File metadata and controls
66 lines (64 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// ExampleWidgetLiveActivity.swift
// ExampleWidget
//
// Created by Brian Smith on 4/30/24.
// Copyright © 2024 The Chromium Authors. All rights reserved.
//
import ActivityKit
import WidgetKit
import SwiftUI
import OneSignalLiveActivities
struct ExampleWidgetLiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: DefaultLiveActivityAttributes.self) { context in
// Lock screen/banner UI goes here\VStack(alignment: .leading) {
VStack {
Spacer()
Text("FLUTTER: " + (context.attributes.data["title"]?.asString() ?? "")).font(.headline)
Spacer()
HStack {
Spacer()
Label {
Text(context.state.data["message"]?.asDict()?["en"]?.asString() ?? "")
} icon: {
Image("onesignaldemo")
.resizable()
.scaledToFit()
.frame(width: 40.0, height: 40.0)
}
Spacer()
}
Text("INT: " + String(context.state.data["intValue"]?.asInt() ?? 0))
Text("DBL: " + String(context.state.data["doubleValue"]?.asDouble() ?? 0.0))
Text("BOL: " + String(context.state.data["boolValue"]?.asBool() ?? false))
Spacer()
}
.activitySystemActionForegroundColor(.black)
.activityBackgroundTint(.white)
} dynamicIsland: { _ 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)
}
}
}