Post

Replies

Boosts

Views

Activity

Strange behaviour with NavigationView and Buttons
I'm getting really strange results when pushing views onto a NavigationView stack and using buttons. This happens in the latest Xcode beta. Sample code: struct TestView: View {     var body: some View {         NavigationView {             VStack {                 NavigationLink("To view 2", destination: View2()) // Doesn't work                 NavigationLink("To view 3", destination: View3()) // Works             }             .navigationTitle("View 1")             .navigationBarTitleDisplayMode(.large)         }     } } struct View2: View {     var body: some View {         VStack {             NavigationLink("To view 3", destination: View3())         }         .navigationTitle("View 2")         .navigationBarTitleDisplayMode(.large) // Setting to .inline makes it work     } } struct View3: View {     var body: some View {         VStack {             Button("Button 1") { print("Button 1") }             Button("Button 2") { print("Button 2") }             Button("Button 3") { print("Button 3") }             Button("Button 4") { print("Button 4") }             Button("Button 5") { print("Button 5") }             Spacer() // Removing this makes it work         }         .navigationTitle("View 3")         .navigationBarTitleDisplayMode(.inline)     } } There are three views. View1 has links to View2 and View3. View2 has a link to View3. View3 has a number of buttons. If I go View1 -> View3, everything works. If I go View1 -> View2 -> View3, the first 2-3 buttons don't work. If I remove the Spacer() from View3, it works. If I change the navigationBarTitleDisplayMode of View2 to .inline, it works. This looks like a bug to me. Are there any workarounds?
0
0
337
Sep ’21