I'm working on a LiveActivity
for an iOS 16 app using SwiftUI
. I can't figure out what's going on with the GeometryReader
. I'm trying to get the dimensions of the entire LiveActivity
view.
In Example (A) below, I've got a VStack
which is set to take up max width and height and contains a GeometryReader
. I'm expecting to see geo.size.height
be 160 (that's the max height of a LiveActivity
on an iPhone 14 Pro Max).
Weirdly, as soon as I include the GeoReader
either here or virtually anywhere else in the view tree, the LiveActivity view height collapses to 64 regardless of any changes in any other views.
//EXAMPLE (A)
struct LiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: Attributes.self) { context in
VStack{
GeometryReader { geo in
Text("Geo Height \(geo.size.height)") //REPORTS 64
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} dynamicIsland: { context in
...
}
}
}
//EXAMPLE (B)
struct LiveActivity: Widget {
var body: some WidgetConfiguration {
ActivityConfiguration(for: Attributes.self) { context in
VStack{
Text("Example A")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay{
GeometryReader { geo in
Text("Geo Height \(geo.size.height)") //REPORTS 160
}
}
} dynamicIsland: { context in
...
}
}
}
I've tried all manner of ways to get everything to expand to the full size but having the GeoReader
anywhere involved somehow negates everything else.
Is this a bug? Is this expected behaviour and I'm missing something? I would expect Example A to report 160 and be the full size.