49.2 Adding Size Support to the Widget View
The changes made to the widget configuration mean that the widget can be displayed in either small or medium size. To make the widget adaptive, the widget view needs to identify the size in which it is currently being displayed. This can be achieved by accessing the widgetFamily property of the SwiftUI environment. Remaining in the WeatherWidget.swift file, locate and edit the WeatherWidgetEntryView declaration to obtain the widget family setting from the environment:
struct WeatherWidgetEntryView: View {
var entry: Provider.Entry
@Environment(\.widgetFamily) var widgetFamily
.
.
Next, embed the subview in a horizontal stack and conditionally display the image for the entry if the size is medium:
struct WeatherWidgetEntryView : View {
var entry: Provider.Entry
@Environment(\.widgetFamily...