1

When using a combination of listRowSeparator and listSectionSeparator being hidden, list row separators don't show up when appending items to the end of the list.

Here is a simple sample that reproduces the problem:

import SwiftUI

struct Item: Identifiable {
    let id: Int
    let text: String
}

struct ContentView: View {
    @State var items: [Item] = []
    var body: some View {
        VStack {
            Button {
                items.append(Item(id: items.count, text: "\(items.count)"))
            } label: {
                Text("Append")
            }
            List {
                Section {
                    ForEach(items) { item in
                        Text(item.text)
                            .listRowSeparator(.visible)
                            .listRowSeparatorTint(Color.red)
                    }
                }
                // Comment out this for row separators to work
                .listSectionSeparator(.hidden, edges: .all)
            }
            .listStyle(.plain)
        }
    }
}

This is happening on iOS 15, only when using plain list style, and only when appending to the end of the list.

Am I doing something wrong, or is there a workaround for this problem?

1 Answer 1

2

Looks like a SwiftUI bug, the below combination can be considered as workaround

Section {
    ForEach(items) { item in
        Text(item.text)
            .listRowSeparatorTint(Color.red)
                     .listRowSeparator(.visible, edges: .bottom)
    }
}
.listSectionSeparator(.hidden, edges: .top)

, which gives

demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! While this doesn't completely work around the issue (it still shows the bottom separator) I think it is a good enough solution.

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.