Is it possible there are issues with previewing Live Activities in Xcode 16.2?
I believe I have everything set up correctly, and the project builds properly with no errors, but the preview canvas is always blank
struct RestTimerLiveActivity: Widget {
var body: some WidgetConfiguration {
if #available(iOS 18.0, *) {
return ActivityConfiguration(for: RestTimerActivityAttributes.self) { context in
RestTimerActivityContent(context: context)
} dynamicIsland: { context in
dynamicIslandContent(context: context)
}
.supplementalActivityFamilies([.small])
} else {
return ActivityConfiguration(for: RestTimerActivityAttributes.self) { context in
RestTimerMediumView(context: context)
} dynamicIsland: { context in
dynamicIslandContent(context: context)
}
}
}
private func dynamicIslandContent(context: ActivityViewContext<RestTimerActivityAttributes>) -> DynamicIsland {
DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Text("Hello")
}
DynamicIslandExpandedRegion(.trailing) {
Text("0:15")
}
DynamicIslandExpandedRegion(.center) {
Text("Timer")
}
DynamicIslandExpandedRegion(.bottom) {
Text("Rest Timer")
}
} compactLeading: {
Text("Hello")
} compactTrailing: {
Text("0:15")
} minimal: {
Text("Hello")
}
}
}
@available(iOS 18.0, *)
struct RestTimerActivityContent: View {
@Environment(\.activityFamily) var activityFamily
var context: ActivityViewContext<RestTimerActivityAttributes>
var body: some View {
switch activityFamily {
case .medium:
RestTimerMediumView(context: context)
case .small:
RestTimerSmallView(context: context)
@unknown default:
fatalError()
}
}
}
struct RestTimerMediumView: View {
var context: ActivityViewContext<RestTimerActivityAttributes>
var body: some View {
Text("Medium!")
}
}
struct RestTimerSmallView: View {
var context: ActivityViewContext<RestTimerActivityAttributes>
var body: some View {
Text("Small!")
}
}
#Preview("Live Activity Content", as: .content, using: RestTimerActivityAttributes.middle) {
RestTimerLiveActivity()
} contentStates: {
RestTimerActivityAttributes.ContentState.idle
RestTimerActivityAttributes.ContentState.paused
RestTimerActivityAttributes.ContentState.running
}
#Preview("Live Activity Dynamic Island Compact", as: .dynamicIsland(.compact), using: RestTimerActivityAttributes.middle) {
RestTimerLiveActivity()
} contentStates: {
RestTimerActivityAttributes.ContentState.idle
RestTimerActivityAttributes.ContentState.paused
RestTimerActivityAttributes.ContentState.running
}