Home > Blockchain >  SwiftUI navigation bar missing in Xcode 14.0 beta 2 (14A5229c)
SwiftUI navigation bar missing in Xcode 14.0 beta 2 (14A5229c)

Time:06-28

I'm assuming I should probably file this as a feedback report with Apple, but posting here in case I am missing something - or if there is new guidance with latest SwiftUI.

This code works as expected in Xcode 13, but in Xcode 14 beta 2, the navigation bar and "Cancel" button are missing. Is this ProgressView with deferred content loading somehow a technique that doesn't work anymore?

import SwiftUI

struct ContentView: View {
    
    @State private var isFlowDetermined = false
    
    var body: some View {

        NavigationView {
            
            //NestedView()
            
            if self.isFlowDetermined {
                NestedView()
            } else {
                ProgressView()
                    .task {
                        await self.determineFlow()
                    }
            }
        }
    }
    
    private func determineFlow() async {
        
        self.isFlowDetermined = true
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct NestedView: View {
    
    var body: some View {
        
        ScrollView {
            Text("Where is the \"Cancel\" button?")
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(Color.green)
    #if !os(macOS)
        .navigationBarTitleDisplayMode(.inline)
    #endif
        .toolbar {
    #if !os(macOS)
            ToolbarItem(placement: .navigationBarLeading) {
                Button("Cancel") {
                    print("got here")
                }
            }
    #endif
        }
    }
}

Navigation bar area with no "Cancel" button or navigation bar.

CodePudding user response:

It seems they optimised toolbar construction (and don't assume it is changed). Anyway I see only one workaround for now:

    NavigationView {

    // .. content

    }
    .id(isFlowDetermined)  // << here !!

Tested with Xcode 14b2 / iOS 16

*Note: NavigationView is deprecated since iOS 16

  • Related