title: SwiftUI Generic Pull to refresh view
body: <p>I have this CustomScrollView which wraps my HomeView and if you pull down it fetches new data.
  It works fine but the thing is that I want to reuse this in multiple views and I do not want to create a copy of this for each of my views.
  I have tried to do this <code>var rootView: View</code> but it throws an error saying <code>View is not convertible to HomeView</code>.</p>
  
  <p>So there are two thing witch should be generic. <code>HomeView()</code> and <code>HomeViewModel</code>.</p>
  
  <p>Any idea how to achieve that?</p>
  
  <pre><code>struct CustomScrollView : UIViewRepresentable {
      var width : CGFloat
      var height : CGFloat
  
      let viewModel = HomeViewModel()
  
      func makeCoordinator() -&gt; Coordinator {
          Coordinator(self, homeViewModel: viewModel)
      }
  
      func makeUIView(context: Context) -&gt; UIScrollView {
          let control = UIScrollView()
          control.refreshControl = UIRefreshControl()
          control.refreshControl?.addTarget(context.coordinator, action: #selector(Coordinator.handleRefreshControl), for: .valueChanged)
  
          let childView = UIHostingController(rootView: HomeView())
  
          childView.view.frame = CGRect(x: 0, y: 0, width: width, height: height)
  
          control.addSubview(childView.view)
          return control
      }
  
      func updateUIView(_ uiView: UIScrollView, context: Context) { }
  
      class Coordinator: NSObject {
          var control: CustomScrollView
          var homeViewModel: HomeViewModel
          init(_ control: CustomScrollView, homeViewModel: HomeViewModel) {
              self.control = control
              self.homeViewModel = homeViewModel
          }
  
          @objc func handleRefreshControl(sender: UIRefreshControl) {
              sender.endRefreshing()
              homeViewModel.loadPackages()
          }
      }
  }
  </code></pre>