'How to make SwiftUI List scroll on tvOS
struct ContentView: View {
private let showList = [
"The Flintstones",
"The Cosby Show",
"The Fresh Prince of Bel Air",
"Full House",
"Seinfeld",
"Friends",
"The Big Bang Theory",
"How I Met Your Mother",
"Grey's Anatomy",
"The Office",
"Law & Order",
"I Love Lucy",
"Family Guy",
"The Simpsons",
"24"
]
var body: some View {
List(showList,id: \.self) { element in
Text(element)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I am trying to use List in a tvOS app, but when I run the app, the list does not scroll. This list scrolls fine when the same code is run on iOS.
How can I make this list scroll on tvOS?
Solution 1:[1]
In TVOS only focusable Elements can be selected via the remote control. So you need to make your list elements focusable. One way would be to make a list of buttons:
List {
ForEach(showList ?? []) { show in
Button(action: {}) {
Text(show)
}
.buttonStyle(CardButtonStyle())
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jussi |
