scrolluinavigationcontrollerswiftuinavigationbardisplaymode

Navigation bar Display Mode is not working Perfectly in SwiftUI


I'm using SwiftUI with Version 11.3.1 (11C504).

I Implement Tab bar on the Screen and that screen will come after the navigation from login Screen.

If navigation displayMode is .automatic so i’am showing a white space(which is in bordered with black line in picture) when I scroll a list in up side. Otherwise navigation title show. And When I set displayMode, .inline so it works perfect. And when I run a project so many time so some time it works perfect and some time showing a space.

i mentioned a white space in the picture with black border.

//ContentView

struct ContentView: View {

    var body: some View {
        HomeTabView()
    }
}

//HomeTabView

struct HomeTabView: View {

    @State private var selection = 0

    //Inclose user intraface of tab View.
    var body: some View {

        TabView(selection: $selection){

            TestListView().tabItem {
                Image(systemName: "book.fill")
                Text("Learn")
            }.tag(0)

            Text("Community").tabItem {
                Image(systemName: "globe")
                Text("Community")
            }.tag(1)

            //Add Notification List on the Screen.
            Text("Notification").tabItem {
                Image(systemName: "bell.fill")
                Text("Notification")

            }.tag(3)

            //Add Account  on the Tab Bar
            Text("Account").tabItem {
                Image(systemName: "person.circle.fill")
                Text("Account")
            }.tag(4)

        }.accentColor(.pink)

            .navigationBarTitle("SwiftUI")
    }

}

TestListView

struct TestListView: View {

    var body: some View {
            VStack{

                List(1...10, id: \.self){ num in
                    ListCards()
                }
              }.edgesIgnoringSafeArea(.all)
       }
}

//ListCards

struct ListCards: View {

    var body: some View {

        ZStack{
        RoundedRectangle(cornerRadius: 16)
                .frame(height: 180)
                .foregroundColor(.white)
                .shadow(radius: 5)

            VStack(alignment: .leading, spacing: 10){

                HStack(alignment: .top){

                    Rectangle()
                        .frame(width: 100, height: 100)
                        .cornerRadius(16)
                        .foregroundColor(.pink)

                    VStack(alignment: .leading, spacing: 4){
                        Text("SwiftUI")
                            .font(.title)

                        Text("Description of title")
                            .foregroundColor(.gray)
                    }
                }
                .padding()

            }.padding(.leading, 2)
        }.padding(.all, 6)
    }
}

enter image description here


Solution

  • You need to change your HomeTabView in this way:

    
    var body: some View {
    
            TabView(selection: $selection) {
                NavigationView {
                    TestListView()
                    .navigationBarTitle("SWIFTUI")
                }.tabItem {
                    Image(systemName: "book.fill")
                    Text("Learn")
                }.tag(0)
    
                NavigationView {
                    Text("Community")
                }.tabItem {
                    Image(systemName: "globe")
                    Text("Community")
                }.tag(1)
    
                //Add Notification List on the Screen.
                NavigationView {
                    Text("Notification")
                }.tabItem {
                    Image(systemName: "bell.fill")
                    Text("Notification")
    
                }.tag(3)
                //Add Account  on the Tab Bar
                NavigationView {
                    Text("Account")
                }.tabItem {
                    Image(systemName: "person.circle.fill")
                    Text("Account")
                }.tag(4)
    
            }.accentColor(.pink)
    
        }
    

    also, remove .edgesIgnoringSafeArea(.all) from TestListView