6

I have a HomeView

NavigationView {
    ZStack {
        VStack {
             NavigationLink(destination: ProfileView()) {
                 if session.userInSession?.activated != 1 {
                     completionText(message: "Complete Your Profile")
                 } else {
                     completionText(message: "Edit Your Profile")
                 }
             }
        }
    }
}

My ProfileView is not wrapped in a navigation view nor has a bar title:

VStack {
    ScrollView(showsIndicators: false) {
        ...
    }
}

But my ProfileView is also accessible from my SettingView

NavigationView {
    VStack(alignment: .leading) {
        List {
            NavigationLink(destination: ProfileView()) {
            }
        }
    }
}

When I access my ProfileView from the setting screen, it displays fine. But when I access it from my HomeView it creates white space at the top:

enter image description here

When I go through Settings its fine:

enter image description here

How can I remove this white space above?

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Gurmukh Singh
  • 1,875
  • 3
  • 24
  • 62

2 Answers2

10

It looks like your HomeView/s NavigationView has .navigationBarTitleDisplayMode(.large) or automatic, which is by default .large, but your SettingView has .navigationBarTitleDisplayMode(.inline) (taking into account divider below < Setting), so you see different height of title bars.

Of course it is assumption due not absent of detailed code, but possible solution to make it same would be add explicit mode for ProfileView, eg:

VStack {
   ScrollView(showsIndicators: false) {
   }
}.navigationBarTitleDisplayMode(.inline)     // << here !!
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690
0

This space is probably an empty title of your NavigationView.

You can try hiding your navigation bar title:

NavigationView {
    ZStack {
        ...
    }
    .navigationBarTitle("")
    .navigationBarHidden(true)
}

As a test try setting .navigationBarTitle("Some title") and see if you still see this empty space or if it's replaced by Some title text.

pawello2222
  • 46,897
  • 22
  • 145
  • 209