There are two list styles that are inactive and produce no result with SwiftUI. Try the .carousel and .sidebar styles to figure it out.
struct ContentView : View {
var body: some View {
List {
Text("Hello")
}
.listStyle(.carousel) // Or .sidebar
}
}
Is this due to the beta (bug), or did I missed something ? The List doesn't appear on my iPhone.
SidebarListStyle is available on macOS only, as CarouselListStyle is only for watchOS.
Here's what sidebar-style list looks like when running on macOS:
Expanded:

Collapsed:

Here's the code (although I'm not sure that an instance of Range or any other one-dimensional sequence is the right choice for this style):
struct ContentView : View {
var body: some View {
List (0..<10) { number in
self.view(forNumber: number)
}
.listStyle(.sidebar)
}
func view(forNumber number: Int) -> some View {
print("number == \(number)")
let ret = Text("#\(number)")
.foregroundColor(.blue)
return ret
}
}
Like others pointed out, the syntax is changing.
Try it this way:
.listStyle(CarouselListStyle())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With