Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI NavigationView remove white space

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?

like image 772
Gurmukh Singh Avatar asked Jun 16 '26 02:06

Gurmukh Singh


1 Answers

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 !!
like image 127
Asperi Avatar answered Jun 20 '26 04:06

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!