Hello,
I just wanted to confirm that ScrollView and prefersDefaultFocus are currently not compatible, at least when building for tvOS
A simple example:
HStack {
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: true) {
VStack {
Button(action: {
resetFocus(in: namespace)
}) {
Text("RESET FOCUS")
}
HStack {
ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], id: \.self) { v in
Button(action: {}) {
Text("ABC \(v)")
}.prefersDefaultFocus(v == 11, in: namespace)
}
}
}.onAppear {
resetFocus(in: namespace)
}
}
}
.focusScope(namespace)
}
}
On load of the view the focus remains on the first button in the HStack. On pressing the RESET FOCUS button focus is applied to the first button visible on the left side of the screen.
Am I missing something here? Is this the way these pieces of SwiftUI currently interact? e.g. prefersDefaultFocus has no effect inside a ScrollView?
Is there a way to focus a specific item in a ScrollView programmatically?
Thanks.