admin管理员组文章数量:1402828
I am building a SwiftUI tvOS app with a LazyVGrid using .adaptive(minimum: 300) columns. The focus behavior works fine for most items, but when an item (like item-9) does not have another item directly below it, the downward movement gets stuck.
Here’s an example of my UI:
Current Focus: item-9 (Highlighted in Red) Goal: When swiping down, I expect the focus to move to item-12, the nearest available item below. Issue: The focus stays stuck on item-9 instead of moving down.
Here is my current code:
struct AdaptiveLazyHGridView: View {
let items = Array(1...22)
var adaptiveColumns = [GridItem(.adaptive(minimum: 300.0), spacing: 10)]
var body: some View {
VStack{
ScrollView(.vertical) {
LazyVGrid(columns: adaptiveColumns) {
ForEach(0 ..< 13) { item in
Button(action: {
}) {
ZStack{
FocusableRectangle()
Text("item - \(item)")
}
}.buttonStyle(CardButtonStyle())
}
}.padding(40)
}
}
}
}
struct FocusableRectangle: View {
@Environment(\.isFocused) var isFocused: Bool
@State var color = Color.blue
var body: some View {
Rectangle()
.fill(color)
.frame(width: 300.0, height: 200.0)
.onChange(of: isFocused) {
color = isFocused ? Color.red : Color.blue
}
}
}
版权声明:本文标题:ios - SwiftUI tvOS LazyVGrid Focus Navigation Issue: Can't Move Down When No Direct Below Item - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744359365a2602467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论