I'm not sure if this is a bug with the iOS 16 betas (currently running iOS Developer Beta 3 on Xcode 14 beta 3) or if I'm doing something wrong (most likely the latter).
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.
I've created a sample app to show this and submitted the bug report to Apple, but on the good chance I'm screwing something up, I'm hoping someone has any idea since I'm not likely to get a response from Apple.
Here's the sample project: 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.