No KeyDispatch or OnBackPress when no currentFocus

This commit is contained in:
LoveSy 2023-03-08 10:36:48 +08:00 committed by John Wu
parent 4709a32641
commit e14f7b6908

View File

@ -20,14 +20,18 @@ abstract class NavigationActivity<Binding : ViewDataBinding> : UIActivity<Bindin
val navigation: NavController get() = navHostFragment.navController
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
return currentFragment?.onKeyEvent(event) == true || super.dispatchKeyEvent(event)
return currentFocus?.let {
currentFragment?.onKeyEvent(event).takeIf { it == true }
} ?: super.dispatchKeyEvent(event)
}
override fun onBackPressed() {
if (currentFragment?.onBackPressed()?.not() == true) {
currentFocus?.let {
if (currentFragment?.onBackPressed() == false) {
super.onBackPressed()
}
}
}
fun NavDirections.navigate() {
navigation.navigate(this)