WidgetKit: Get size of the widget for placeholder view

Hey,

I need to know the size of the widget in advance in order to create a proper UI for my widget. This works great by using the displaySize property provided by the TimelineProviderContext.

However so far I did not find any way to get the widget size for my placeholder view. Since I don't have a provider, I have no TimelineProviderContext and thus no displaySize.

Is there any way to know the widget size in the placeholder?
Here is a code snippet where I would need to pass the widget size to the PlaceholderView view:

Code Block swift
struct MyWidget: Widget {
public var body: some WidgetConfiguration {
StaticConfiguration(kind: myWidgetKind, provider: Provider(), placeholder: PlaceholderView()) { entry in
WidgetEntryView(entry)
}
.configurationDisplayName("Display Name")
.description("Description")
.supportedFamilies([.systemSmall, .systemMedium])
}
}


Thanks in advance!
Try this:
Code Block
GeometryReader { geo in
Image(uiImage: UIImage(data: UserDefaults.standard.data(forKey: "ImageData")!)!)
.resizable()
.scaledToFill()
.frame(width: geo.size.width, height: geo.size.height)
.clipped()
}


Thanks for the suggestion. However this approach would not help me since I want to generate different image data depending on the widget size. The suggested approach is taking one image and scaling it to fit the widget which is slightly different.
It appears that this issue has been addressed in Xcode 12.0 beta 3 with the new placeholder APIs. The provider should now implement:
Code Block
public func placeholder(with: Self.Context) -> Self.Entry


Thanks to this new API, the placeholder should have access to the context and should be able to use the displaySize.


WidgetKit: Get size of the widget for placeholder view
 
 
Q