As seen in the WWDC 24 video, it’s possible to visualize all live activity UIs in the previewer. However, I’m encountering a Cannot preview this file
error.
struct LiveActivityTest: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: CustomLAData.self, content: {context in
VStack{
Image(systemName: "globe")
.resizable()
Text("Text 1")
}
}, dynamicIsland: {context in
let timeRange = Date()...Date.now+100
return DynamicIsland{
DynamicIslandExpandedRegion(.leading, content: {
Text("Text 1")
.bold()
})
DynamicIslandExpandedRegion(.trailing, content: {
Text(timerInterval: timeRange, pauseTime: timeRange.lowerBound, countsDown: true)
.font(.system(size: 22,weight: .bold))
.multilineTextAlignment(.trailing)
})
DynamicIslandExpandedRegion(.bottom){
Text("Bottom Text")
}
} compactLeading: {
Text("Compact leading")
} compactTrailing: {
Image(systemName:"globe")
} minimal: {
Image(systemName:"globe")
}
})
}
}
#Preview(as: .dynamicIsland(.compact), using: CustomLAData(), widget: {
LiveActivityTest()
}, contentStates: {
CustomLAData.State()
CustomLAData.State(isLoading:true)
})
struct CustomLAData : ActivityAttributes{
typealias ContentState = State
struct State : Codable,Hashable{
var isLoading = false
}
}
I tried using different preview macros, but I still couldn’t identify where I made a mistake
Note : I have added the Liveactivity widget to widget bundle.