title: SwiftUI Pass Value from Geometry Reader to Function
body: <p>I have a view which uses Geometry Reader to calculate how large the image area should be:</p>
  
  <pre><code>GeometryReader { metrics in
      ZStack{
          self.image
             .resizable()
             .frame(width:  (metrics.size.height - 10) * 0.561403509 , height: metrics.size.height - 10, alignment: .top)
             .clipped()
      }
  }
  </code></pre>
  
  <p>But I have a function where I want to use the frame height and width calculated by the GeometryReader in order to crop the image.</p>
  
  <p>I have a separate function which crops the image when a button is pressed:</p>
  
  <pre><code> DownloadImageButton(prepareImagefunction: { self.prepareImage() })
  </code></pre>
  
  <p>Which then calls a prepareImage function:</p>
  
  <pre><code>func prepareImage( ) {
   // In order for image cropping to work, we need the equivalent of view.bounds in order to adjust the crop so that it correctly measures the crop area. We need metrics.width and metrics.height 
   var adjustmentScaleForDisplaySize = targetSize.width / metrics.width
  </code></pre>
  
  <p>Note that the GeometryReader is a child of the parent view where prepareImage is called. Therefore, ideally, the child would save the metrics values in an EnvironmentObject or Binding to the parent.</p>