Skip to content

Instantly share code, notes, and snippets.

@iosdevie
Created May 29, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iosdevie/ec75837ef153843f952238001c376981 to your computer and use it in GitHub Desktop.
Save iosdevie/ec75837ef153843f952238001c376981 to your computer and use it in GitHub Desktop.
struct CustomScrollView : UIViewRepresentable {
var width : CGFloat
var height : CGFloat
let modelData = DataModel(modelData: [Model(title: "Item 1"), Model(title: "Item 2"), Model(title: "Item 3")])
func makeCoordinator() -> Coordinator {
Coordinator(self, model: modelData)
}
func makeUIView(context: Context) -> UIScrollView {
let control = UIScrollView()
control.refreshControl = UIRefreshControl()
control.refreshControl?.addTarget(context.coordinator, action:
#selector(Coordinator.handleRefreshControl),
for: .valueChanged)
let childView = UIHostingController(rootView: SwiftUIList(model: modelData))
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 model : DataModel
init(_ control: CustomScrollView, model: DataModel) {
self.control = control
self.model = model
}
@objc func handleRefreshControl(sender: UIRefreshControl) {
sender.endRefreshing()
model.addElement()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment