Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SidebarListStyle no longer displays collapse/expand buttons - Xcode 15 beta 6

Tags:

swiftui

ios17

With a List embedded in a VStack, in iOS 16 adding a .listStyle(SidebarListStyle()) would add the collapse/expand buttons to each Section. Running Xcode 15 beta 6 and the buttons are no longer displayed on each Section. I found the following New Feature in Apple's documentation for SwiftUI, not sure if it's the root cause.

From iOS & iPadOS 17 Beta 6 Release Notes:

Lists using the SidebarListStyle hosted in primary column of a UIKit UISplitNavigationController were previously rendering with an insetGrouped appearance. With this change they will render as the expected sidebar appearance similar to if the List were hosted in a SwiftUI NavigationSplitView. (96909195)

Is there any other listStyle that will add these collapse/expand buttons back or is this a potential bug in Xcode's beta? Hoping to not make custom section headers.

            List {
                ForEach(searchResults, id: \.Id) { log in
                    if log.logs?.count ?? 0 > 0 && vm.filterLogs(logs: log.logs!).count > 0 {
                        Section(header: Text(vm.getSectionText(log: log))
                            .font(.title3)
                            .fontWeight(.bold)
                            .foregroundColor(.primary),
                                content: {
                            ForEach(vm.filterLogs(logs: log.logs!), id: \.Id) { record in
                                Button(action: {
                                    vm.selectedLog = log
                                    vm.selectedRecord = record
                                    isShowingDetailSheet.toggle()
                                }, label: {
                                    RecordView(record: record)
                                })
                            }
                        })
                    }
                }
            }
            .listStyle(SidebarListStyle())

I have tried other listStyle options, but none of them add the collapse/expand buttons.

like image 853
nwolfe09 Avatar asked Dec 15 '25 06:12

nwolfe09


1 Answers

There's a new initializer for Section in iOS 17, which takes a boolean Binding isExpanded. This value, together with the .sidebar list style, brings back the arrow and functionality to expand/collapse the section.

Here's a small example:

struct TestView: View {
    @State var isExpanded = true
    
    var body: some View {
        List {
            Section(isExpanded: $isExpanded) {
                Text("one")
                Text("two")
                Text("three")
            } header: {
                Text("Section Title")
            }
        }
        .listStyle(.sidebar)
    }
}

Preview of the example code

In your case, however, you would need to find a way to have one binding for each of your log items.

like image 86
vollkorntomate Avatar answered Dec 16 '25 23:12

vollkorntomate