Created
September 20, 2022 17:35
-
-
Save ashishkakkad8/42d489abe2d11883caf714872e40a9a2 to your computer and use it in GitHub Desktop.
Live Activity Sample Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LiveActivitySample.swift | |
// LiveActivitySample | |
// | |
// Created by Ashish Kakkad on 20/09/22. | |
// | |
import WidgetKit | |
import SwiftUI | |
struct LiveActivityExpandedViewSample: View { | |
var state: ActivityAttributesSample.ContentState | |
var body: some View { | |
VStack { | |
Text ("Hello, CENTER") | |
Text(state.value) | |
.foregroundColor(.secondary) | |
} | |
.activityBackgroundTint(.gray) | |
} | |
} | |
@main | |
struct LiveActivitySample: Widget { | |
let kind: String = "LiveActivitySample" | |
var body: some WidgetConfiguration { | |
ActivityConfiguration(for: ActivityAttributesSample.self) { context in | |
LiveActivityExpandedViewSample(state: context.state) | |
} dynamicIsland: { context in | |
DynamicIsland { | |
DynamicIslandExpandedRegion(.center) { | |
LiveActivityExpandedViewSample(state: context.state) | |
} | |
DynamicIslandExpandedRegion(.leading) { | |
Text("LEFT") | |
} | |
DynamicIslandExpandedRegion(.trailing) { | |
Text("RIGHT") | |
} | |
DynamicIslandExpandedRegion(.bottom) { | |
Text("BOTTOM") | |
} | |
} compactLeading: { | |
Image(systemName: "capsule") | |
} compactTrailing: { | |
EmptyView() | |
} minimal: { | |
EmptyView() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment