#Preview a Widget placeholder?

While I am able to use #Preview to preview a Widget, it seems to be not possible to easily preview a Widget placeholder. With a "classic" preview I can use .redacted(reason: .placeholder), but this has limitation e.g. it will ignore .contentMarginsDisabled()

struct MyWidget_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀"))
            MyWidgetView(entry: SimpleEntry(date: .now, emoji: "😀"))
                .redacted(reason: .placeholder)
        }
        .previewContext(WidgetPreviewContext(family: .systemMedium))
        .containerBackground(.white, for: .widget)
    }
}

If I use #Preview, the .redacted modifier won't work, and I seem to have to put it in the MyWidget implementation.

#Preview(as: .systemMedium) {
    MyWidget()
} timeline: {
    SimpleEntry(date: .now, emoji: "😀")
    SimpleEntry(date: .now, emoji: "🤩")
}

Am I missing something?

Answered by Developer Tools Engineer in 806232022

Hi,

Sorry to hear you are having problems getting redactions in previews working. Have you tried playing around with the options available in the Device Settings and/or the Variations grid?

Accepted Answer

Hi,

Sorry to hear you are having problems getting redactions in previews working. Have you tried playing around with the options available in the Device Settings and/or the Variations grid?

#Preview a Widget placeholder?
 
 
Q