title: How to get the actual view rendered size and position in SwiftUI?
body: <p>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 <code>Text(&quot;Foo&quot;)</code> size in the SwiftUI code below?</p>
  <p><a href="https://developer.apple.com/documentation/swiftui/geometryreader" rel="nofollow noreferrer"><code>GeometryReader</code></a>  can be used to get the parent proposed <code>size</code> and safe area inset via <code>safeAreaInsets</code> and these information is defined inside <a href="https://developer.apple.com/documentation/swiftui/geometryproxy" rel="nofollow noreferrer"><code>GeometryProxy</code></a>. You can see from the screenshot below, the proposed size to <code>VStack</code> is <code>300</code> width and <code>300</code> height and the actual size for the <code>VStack</code> is unknown.</p>
  <p><a href="https://i.stack.imgur.com/5gvD1m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5gvD1m.png" alt="enter image description here" /></a></p>
  <pre><code>struct FooView: View {
      var body: some View {
          GeometryReader { geometryProxy in
              VStack {
                  Text(&quot;\(geometryProxy.size.height), \(geometryProxy.size.width)&quot;)
                  Text(&quot;Foo&quot;)
              }
              .background(Color.green)
          }
          .frame(width: 300, height: 300)
          .background(Color.blue)
      }
  }
  </code></pre>