I am trying to set onFocusChange
and click action function on a view. But onFocusChange
is never called.
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .center, spacing: 5) {
ForEach(self.videos, id: .id) { video in
Button(action: {
print("clicked")
}){
ItemView(vid: video)
.cornerRadius(5).padding(1)
}.focusable(true, onFocusChange: {
hasFocus in
print("focused")
})
}
}
}
If I move the button view inside the ItemView()
, the onFocusChange
works but the click action doesn't.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…