Is it possible to see a preview of the Live Activity UI we design? For a regular widget, we pass in a WidgetPreviewContext modifier where we specify the size of the widget to preview. Is it possible to do something similar to see how the live activity would appear without having to run the app and then see how the live activity appears on the Lock Screen?
iOS 16 Live Activity + SwiftUI Previews
did you found any solution to view and test live activity or dynamic island.
Did you find the way? I am also looking for... Apple's document is terrible....
@jabhiji @waohqc @amit12we I found a way!
I initialize some dummy ActivityAttributes
and ContentState
then use
attributes.previewContext(contentState, viewKind: .dynamicIsland(.compact))
Full example
struct HuntLiveActivityWidget_Previews: PreviewProvider {
static let attributes = HuntAttributes.init(huntID: "1234",
huntName: "Hunt name",
numberOfClues: 10)
static let contentState = HuntAttributes.ContentState(currentClueText: "This is the current clue to be solved.",
currentClueIndex: 0,
currentHuntProgress: 0.1)
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")
}
}