NavigationView extra sapce

the code below is a swiftui ios project with catalyst turned on. when i run this on the mac, and click on the accounts item in the first navigation view it loads the accounts view fine but there is a few lines of extra space above the header. how do i remove that space?



import SwiftUI

struct ContentView: View {
   
    init() {
        UITableView.appearance().separatorStyle = .none
    }
   
    var body: some View {
        NavigationView {
            List {
                NavigationLink("Accounts", destination: AccountsView())
                NavigationLink("Budgets", destination: BudgetsView())
            }
            .navigationBarTitle("Sidebar")
            .navigationBarHidden(true)
        }
    }
   
}

struct AccountsView: View {
   
    @State var accounts: [Account] = [
        Account(name: "Account #1"),
        Account(name: "Account #2"),
        Account(name: "Account #3"),
        Account(name: "Account #4"),
    ]
   
    var body: some View {
        NavigationView {
            List(accounts) { account in
                NavigationLink(account.name, destination: Text(account.name))
            }
            .navigationBarTitle("Accounts")
        }.background(Color(.purple))
    }
   
}
struct BudgetsView: View {
    var body: some View {
        Text("Budgets")
    }
}

struct Account: Identifiable {
    var id: UUID = UUID()
    var name: String
}

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

hi,


removing the NavigationView wrapper in the AccountsView (lines 32/37) should solve your problem.


(tested on XCode 11.3.1, simulator running iO 13.3, on a Mac running Catalina 10.15.3.)


hope that helps,

DMG

If I did that I couldn’t use the navigation link to the Accountdetailview

hi,


you said "If I did that I couldn’t ..."


you didn't say "I did that and it doesn't ... and here's my updated code ..."


you might look back at this related thread of a few days ago: https://forums.developer.apple.com/thread/128454


EDIT ADDED 4 DAYS AFTER THIS RESPONSE: i hope you have not chosen to not continue because my answer might have been construed as off-putting or dismissive. we really do like to help people in this forum, but we really also do like to have code in front of us to work with. nevertheless, i'll repeat my initial response, in case it was not clear what i meant by "remove the navigation wrapper." i still claim that if you comment out lines 32 and 37 in your original code, things will work as (i think) you intended.


hope that helps,

DMG

I am sorry i took so long to respond. i was not aware that this forum did not email me when i have a response like reddit does. And i stopped checking on it every day like i did when i first posted it. I tried your method and it did improve it a little but it was still not what i wanted. When i clicked on a link in the second navigation view it would cover that navigation list with the detail view. I decided to scrap the methodology that i was trying for and to go with a segmented button on the toolbar for tabs on catalyst and then tabview on the ios code. Thanks for all your help.

NavigationView extra sapce
 
 
Q