Added forced checks on view being attached to window before performing hiding on it

This commit is contained in:
Viktor De Pasquale 2020-09-22 16:12:41 +02:00 committed by John Wu
parent bf84dd6518
commit 3c0630bfc0

View File

@ -148,6 +148,32 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
val topView = binding.mainToolbarWrapper
val bottomView = binding.mainBottomBar
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
!binding.mainBottomBar.isAttachedToWindow
) {
binding.mainBottomBar.viewTreeObserver.addOnWindowAttachListener(object :
ViewTreeObserver.OnWindowAttachListener {
init {
val listener =
binding.mainBottomBar.tag as? ViewTreeObserver.OnWindowAttachListener
if (listener != null) {
binding.mainBottomBar.viewTreeObserver.removeOnWindowAttachListener(listener)
}
binding.mainBottomBar.tag = this
}
override fun onWindowAttached() {
requestNavigationHidden(hide)
}
override fun onWindowDetached() {
}
})
return
}
val topParams = topView.layoutParams as? CoordinatorLayout.LayoutParams
val bottomParams = bottomView.layoutParams as? CoordinatorLayout.LayoutParams