1

In SwiftUI, whenever a NavigationLink is inside a form, the destination view also seems to "styled" as if it's also in the form. This makes sense for pickers and such, but I'm just wanting to display a list of messages for an internal app that includes a simple email client. See recreated example below.

import SwiftUI

struct BasicRootView: View {
    var body: some View {
        NavigationView {
            VStack(alignment: .leading) {
                MailboxListView()
                Spacer()
            }
        }
    }
}

struct FormRootView: View {
    var body: some View {
        NavigationView {
            Form {
                MailboxListView()
            }
        }
    }
}


struct MessageListView: View {
    var body: some View {
        List(0..<30) { i in
            Text("Message \(i)")
        }
        .navigationBarTitle("Mailbox", displayMode: .inline)
    }
}

struct MailboxListView: View {
    var body: some View {
        Section(header: Text("[email protected]").font(.headline)) {
            NavigationLink(destination: MessageListView()) {
                HStack {
                    Image(systemName: "tray")
                        .font(.body)
                    Text("Inbox")
                }
            }
            NavigationLink(destination: MessageListView()) {
                HStack {
                    Image(systemName: "paperplane")
                        .font(.body)
                    Text("Sent")
                }
            }
            NavigationLink(destination: MessageListView()) {
                HStack {
                    Image(systemName: "bin.xmark")
                        .font(.body)
                    Text("Spam")
                }
            }
            NavigationLink(destination: MessageListView()) {
                HStack {
                    Image(systemName: "trash")
                        .font(.body)
                    Text("Trash")
                }
            }
        }
        .navigationBarTitle("Accounts")
    }
}

The BasicRootView above doesn't look as I want it to, but the destination of its links looks like a normal list. So when I try to put it in a form to get the layout and look I'm going for, the destination list now itself looks like it's in a form as well, an unnecessary gap between the start of the list and the nav bar.

BadFolderView

^^ No good

GoodMessageView

^^ Good

GoodFolderView

^^ Good

BadMessageView

^^ No Good

Any way to "shed" the form in a destination view?

1
  • Sorry, forgot to mention, Xcode 11 Beta 7, iOS 13 Beta 8 (NOT 13.1 Beta) Commented Sep 9, 2019 at 19:08

1 Answer 1

2

Just define the listStyle for both of your lists:

struct FormRootView: View {
    var body: some View {
        NavigationView {
            List {
                MailboxListView()
            }   .listStyle(GroupedListStyle())
        }
    }
}


struct MessageListView: View {
    var body: some View {
        List(0..<30) { i in
            Text("Message \(i)")
            }   .listStyle(PlainListStyle())
        .navigationBarTitle("Mailbox", displayMode: .inline)
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can confirm adding this to the Destination also works: NavigationLink(destination: DestinationView().listStyle(PlainListStyle())) { NavigationLinkView() }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.