I'm trying to add a SwiftUI view to my existing UIKit app which uses UINavigationController. When I push the SwiftUI view (using UIHostingController), the destination (SwiftUI) view has this weird animation bug where the content loads for a split second, then it will jump up to the correct position. I'm setting the title for the NavigationBar to be .inline or blank completely and it seems like the title is initially being rendered in the .large format then, once it changes it to .inline, the content moves up to fill in the space once taken by the Title.
Any suggestions would be appreciated. I've already filed a feedback with Apple.
I've created a sample project that demonstrates this: https://github.com/rjeitani/testNavBarIssue
Relevant code:
// The UIKit ViewController
func showSwiftUIView() {
let vc = UIHostingController(rootView: SwiftUIView())
self.navigationController?.pushViewController(vc, animated: true)
}
// SwiftUI View
import SwiftUI
import Charts
struct SwiftUIView: View {
var body: some View {
testView()
}
}
struct testView: View {
@State private var pickerState: Bool = false
var body: some View {
VStack (alignment: .leading) {
Text("Test").padding()
Chart {
BarMark(x: .value("Month", 1), y: .value("Count", 3))
BarMark(x: .value("Month", 2), y: .value("Count", 7))
BarMark(x: .value("Month", 3), y: .value("Count", 2))
BarMark(x: .value("Month", 4), y: .value("Count", 1))
}
} .navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
Here's a screen recording of the bug. You can see near the end that the "Test" label and the whole Chart itself jump upwards after the view has loaded.