And here is the working solution for tvOS 15:
struct ContentView: View {
@FocusState var focusedItem: String?
@State var items = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 4)
var body: some View {
ScrollView() {
LazyVGrid(columns: columns) {
ForEach(items, id: \.self) { item in
Button {
} label: {
ItemView(title: item)
}
.focused($focusedItem, equals: item)
.onMoveCommand { moveCommandDirection in
guard let index = items.firstIndex(where: {$0 == item}) else {
return
}
if moveCommandDirection == .down, index >= items.count - columns.count {
focusedItem = items.last
}
}
.padding(.bottom, 8)
}
}
}
}
}
If you have any workaround for tvOS 14 I'll be appreciated it.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: