title: ios swift app: screen snapshot returns blank image when the scrollview is very long
body: <p>Here below is my sample demo view and a swift button to trigger it.</p>
  <p>The wired thing is: when the screenshot image is very long (like, we have more than 40 items below), it only saves an empty image. However, it can store an valid image with all the content, when there are fewer items.</p>
  <p>note: the xcode project target is &quot;ios 15.0&quot;.</p>
  <p>Anything wrong with my code? please help.</p>
  <pre><code>struct ContentView: View {
  
      ... ...
  
      func getContentView() -&gt; some View {
          ScrollView {
              ForEach(1...42, id:\.self) { event in
                  Text(&quot;event \(event)&quot;)
                      .frame(width: 400, height: 80, alignment: .center)
              }
          }
          .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
          .padding(EdgeInsets(top: 0, leading: 0, bottom: 40, trailing: 0))
      }
  
      ... ...
  
      var body: some View {
          GeometryReader { geometry in
              VStack {
                  getContentView()
  
                  Button(action: {
                      let dataView = getContentView()
                      let image = dataView.snapshot(size: geometry.size)
                      UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
                  }) {
                      HStack(alignment: .center, spacing: 0) {
                          Image(systemName: &quot;photo&quot;)
                          Text(&quot;homepage_action_save&quot;)
                      }
                  }
      ... ...
  }
  
  
  extension View {
      func snapshot(size: CGSize) -&gt; UIImage {
          let controller = UIHostingController(rootView: self)
          let view = controller.view
  
          var targetSize = controller.view.intrinsicContentSize
          targetSize.width = size.width
          view?.bounds = CGRect(origin: .zero, size: targetSize)
          view?.backgroundColor = .clear
  
          let renderer = UIGraphicsImageRenderer(size: targetSize)
          return renderer.image { _ in
              view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
          }
      }
  }
  </code></pre>