Hi guys,
I am migrating my widgets to iOS 17 and because I already manage my layout margins, I just want to disable to new built-in widget content margins.
I did it by using ".contentMarginsDisabled()" on the WidgetConfiguration and it works fine at run time.
WIDGET CODE
struct MyWidget: Widget {
let kind: String = "MyWidget"
var body: some WidgetConfiguration {
return IntentConfiguration(kind: kind, intent: MyWidgetIntent.self, provider: WidgetProvider<MyWidgetIntent>()) { entry in
WidgetView<MyWidgetIntent>(entry: entry)
}
.configurationDisplayName("My Widget")
.supportedFamilies([WidgetFamily.systemMedium])
.contentMarginsDisabled() // <-- HERE
}
}
RESULT
Nevertheless, when previewing the WidgetView in a WidgetPreviewContext I didn't find anyway to disable the content margins (because manipulating directly the view and not a WidgetConfiguration).
PREVIEW CODE
struct MyWidget_Previews: PreviewProvider {
static var previews: some View {
WidgetView<MyWidgetIntent>(entry: WidgetEntry<MyWidgetIntent>())
// .padding(-16) Need to add this negative padding to disable margin
.previewContext(
WidgetPreviewContext(family: .systemMedium))
}
}
Do you know how to disable the content margins for widget preview?