Created
July 15, 2019 05:50
-
-
Save mishimay/81beb17814949a9305ad4f5022a38ae5 to your computer and use it in GitHub Desktop.
Bridge UIScrollView to SwiftUI
This file contains hidden or 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 MyScrollView: UIViewRepresentable { | |
let swiftUIView: AnyView | |
func makeUIView(context: UIViewRepresentableContext<ContentView.MyScrollView>) -> UIView { | |
let hosting = UIHostingController(rootView: swiftUIView) | |
let width = UIScreen.main.bounds.width | |
let size = hosting.view.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)) | |
hosting.view.frame = CGRect(x: 0, y: 0, width: width, height: size.height) | |
let view = UIScrollView() | |
view.alwaysBounceVertical = true | |
view.addSubview(hosting.view) | |
view.contentSize = CGSize(width: width, height: size.height) | |
return view | |
} | |
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<ContentView.MyScrollView>) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote an improved code.
Please check this.
https://gist.github.com/mishimay/b823280bd91d16474362376029321752