This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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