The question is how to get the actual viewed rendered size and position in a parent view? In other word, how to get the actual Text("Foo") size in the SwiftUI code below?
GeometryReader can be used to get the parent proposed size and safe area inset via safeAreaInsets and these information is defined inside GeometryProxy. You can see from the screenshot below, the proposed size to VStack is 300 width and 300 height and the actual size for the VStack is unknown.
struct FooView: View {
var body: some View {
GeometryReader { geometryProxy in
VStack {
Text("\(geometryProxy.size.height), \(geometryProxy.size.width)")
Text("Foo")
}
.background(Color.green)
}
.frame(width: 300, height: 300)
.background(Color.blue)
}
}


