光刻FocusChangedEvent一直被触发
我正在尝试编写一个Android TV演示,将FocusChangedEvent添加到ListItemSpec来更改项目状态。该演示非常简单,只需将ClickEvent从barbones(demo)更改即可。并发现hasFocus处于RecyclerCollectionComponent状态的项目一直在不断enter code here
ging。我发现列表中的第一项一直失去关注并重新获得关注。和电视遥控装置难以滑动列表。我检查了dispatchKeyEvent的keyevent是否出现,但是什么也没有。
@OnCreateLayout
fun onCreateLayout(
c: ComponentContext,
@Prop color: Int,
@Prop title: String,
@Prop subtitle: String,
@State isFocus: Boolean
): Component = Column.create(c)
.paddingDip(ALL, 16f)
.focusable(true)
.clickHandler(ListItem.onFocusChanged(c))
.backgroundColor(if (isFocus) Color.GRAY else Color.WHITE)
.child(
Text.create(c)
.text(title)
.textSizeSp(40f))
.child(
Text.create(c)
.text(subtitle)
.textSizeSp(20f))
.build()
@OnUpdateState
fun bgColorChange(isFocus: StateValue<Boolean>) {
isFocus.set(!isFocus.get()!!)
}
@OnEvent(FocusChangedEvent::class)
fun onFocusChanged(c: ComponentContext, @FromEvent hasFocus:Boolean) {
logd("onFocusChanged","$hasFocus")
ListItem.bgColorChange(c)
}
2019-06-24 11:35:41.626 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.659 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.662 19560-19560/com.demo.lithodemo D/onFocusChanged: false
2019-06-24 11:35:41.664 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.697 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.700 19560-19560/com.demo.lithodemo D/onFocusChanged: false
2019-06-24 11:35:41.705 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.742 19560-19560/com.demo.lithodemo D/onFocusChanged: true
2019-06-24 11:35:41.744 19560-19560/com.demo.lithodemo D/onFocusChanged: false