I try to use UIHostingController in UIViewControllerRepresentable inside SwiftUI NavigationView.
But I noticed a problem with this on iOS 16 the content in HostinController clipped after being moved to another view in NavigationLink.
Code:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView {
VStack {
TosterView { Color.green }
.frame(height: 170)
NavigationLink(destination: { Text("Destination")}, label: { Text("Go to destination")})
Color.orange.frame(height: 900)
}
}
}
}
}
public struct TosterView<PageContent: View>: UIViewControllerRepresentable {
let contentForData: () -> PageContent
public func makeUIViewController(context: Context) -> UIHostingController<PageContent> {
UIHostingController(rootView: contentForData())
}
public func updateUIViewController(_ uiViewController: UIHostingController<PageContent>, context: Context) {}
}
P.S. Please don't recommend to use UIViewRepresentable or use ViewController with background Green