Fixed core UI elements not behaving properly after recreating

This commit is contained in:
Viktor De Pasquale 2019-11-21 14:24:14 +01:00
parent 6379108a75
commit 8a86b30fd1

View File

@ -85,6 +85,10 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
if (savedInstanceState != null) {
onTabTransaction(null, -1)
onFragmentTransaction(null, FragNavController.TransactionType.PUSH)
if (!navigation.isRoot) {
requestNavigationHidden(animate = false)
}
}
}
@ -118,6 +122,11 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
fragment: Fragment?,
transactionType: FragNavController.TransactionType
) {
binding.mainToolbarWrapper.animate()
.translationY(0f)
.setInterpolator(FastOutSlowInInterpolator())
.start()
setDisplayHomeAsUpEnabled(!navigation.isRoot)
requestNavigationHidden(!navigation.isRoot)
}
@ -134,13 +143,19 @@ open class MainActivity : CompatActivity<MainViewModel, ActivityMainMd2Binding>(
}
}
internal fun requestNavigationHidden(hide: Boolean = true) {
internal fun requestNavigationHidden(hide: Boolean = true, animate: Boolean = true) {
val lapam = binding.mainBottomBar.layoutParams as ViewGroup.MarginLayoutParams
val height = binding.mainBottomBar.measuredHeight
val verticalMargin = lapam.let { it.topMargin + it.bottomMargin }
val maxTranslation = height + verticalMargin
val translation = if (!hide) 0 else maxTranslation
if (!animate) {
binding.mainBottomBar.translationY = translation.toFloat()
binding.mainBottomBar.isVisible = !hide
return
}
binding.mainBottomBar.animate()
.translationY(translation.toFloat())
.setInterpolator(FastOutSlowInInterpolator())