Skip to content

Commit

Permalink
Fix currentFocus
Browse files Browse the repository at this point in the history
Looks like currentFocus does not always exist even after setContentView,
so I hereby use another way to check if setContentView is called
  • Loading branch information
yujincheng08 authored and topjohnwu committed Mar 10, 2023
1 parent 382568b commit 3cf66d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ abstract class NavigationActivity<Binding : ViewDataBinding> : UIActivity<Bindin
val navigation: NavController get() = navHostFragment.navController

override fun dispatchKeyEvent(event: KeyEvent): Boolean {
return currentFocus?.let {
currentFragment?.onKeyEvent(event).takeIf { it == true }
} ?: super.dispatchKeyEvent(event)
return if (binded && currentFragment?.onKeyEvent(event) == true) true else super.dispatchKeyEvent(event)
}

override fun onBackPressed() {
currentFocus?.let {
if (binded) {
if (currentFragment?.onBackPressed() == false) {
super.onBackPressed()
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/topjohnwu/magisk/arch/UIActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class UIActivity<Binding : ViewDataBinding> : BaseActivity(), ViewModel
protected lateinit var binding: Binding
protected abstract val layoutRes: Int

protected val binded get() = ::binding.isInitialized

open val snackbarView get() = binding.root
open val snackbarAnchorView: View? get() = null

Expand Down

0 comments on commit 3cf66d1

Please sign in to comment.