List within a DisclosureGroup

Hello,

I need to create a NavigationView with a List inside a DisclosureGroup but the list is not visible. Actually I did see one time a grey area of a list background.

This is the code what I use.

Code Block struct SideBarView: View {
@State private var revealDetails = false
var body: some View {
VStack {
DisclosureGroup("Show some Text", isExpanded: $revealDetails) {
VStack{
Text("Some Text...")
.padding()
.lineLimit(5)
Divider()
List(){
Text("Hello, world!").padding()
Text("Hello, world!").padding()
Text("Hello, world!").padding()
}.listStyle(SidebarListStyle())
Divider()
}
.padding()
}
Spacer()
}
}
}


Any suggestions, or could it be a beta SwiftUI 2 bug?

Thank you

Accepted Reply

Try this code and see if it's what you're looking for. The gray area of the list background you saw is from the .listStyle(SidebarListStyle()) modifier you have in there. If you remove that the gray area goes away.

I hope this helps.
  • Dan

Code Block
struct ContentView: View {
@State private var revealDetails = false
var body: some View {
VStack {
List {
DisclosureGroup("Show some Text", isExpanded: $revealDetails) {
Text("Some Text...")
.padding()
Text("Hello, world!").padding()
Text("Hello, world!").padding()
Text("Hello, world!").padding()
}
}.listStyle(SidebarListStyle())
.padding()
Spacer()
}
}
}


Replies

Try this code and see if it's what you're looking for. The gray area of the list background you saw is from the .listStyle(SidebarListStyle()) modifier you have in there. If you remove that the gray area goes away.

I hope this helps.
  • Dan

Code Block
struct ContentView: View {
@State private var revealDetails = false
var body: some View {
VStack {
List {
DisclosureGroup("Show some Text", isExpanded: $revealDetails) {
Text("Some Text...")
.padding()
Text("Hello, world!").padding()
Text("Hello, world!").padding()
Text("Hello, world!").padding()
}
}.listStyle(SidebarListStyle())
.padding()
Spacer()
}
}
}


Hi Dan

It did helps. But with a quit different layout.
I know about the grey area where it comes from, but did expect the whole list. Because of the grey background it looks to me that it should be posable to have the list inside a disclosuregroup.
Next step will be, adding several element in a working navigationView.

Thank you.