MainActivity: Fix incorrect UI states when activity recreated with dialog controller (#7325)
This commit is contained in:
parent
6aee4fc464
commit
3c3d787a2b
@ -541,15 +541,28 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun syncActivityViewWithController(
|
private fun syncActivityViewWithController(
|
||||||
to: Controller? = router.backstack.lastOrNull()?.controller,
|
to: Controller? = null,
|
||||||
from: Controller? = null,
|
from: Controller? = null,
|
||||||
isPush: Boolean = true,
|
isPush: Boolean = true,
|
||||||
) {
|
) {
|
||||||
if (from is DialogController || to is DialogController) {
|
var internalTo = to
|
||||||
return
|
|
||||||
}
|
if (internalTo == null) {
|
||||||
if (from is PreferenceDialogController || to is PreferenceDialogController) {
|
// Should go here when the activity is recreated and dialog controller is on top of the backstack
|
||||||
return
|
// Then we'll assume the top controller is the parent controller of this dialog
|
||||||
|
val backstack = router.backstack
|
||||||
|
internalTo = backstack.lastOrNull()?.controller
|
||||||
|
if (internalTo is DialogController || internalTo is PreferenceDialogController) {
|
||||||
|
internalTo = backstack.getOrNull(backstack.size - 2)?.controller ?: return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Ignore changes for normal transactions
|
||||||
|
if (from is DialogController || internalTo is DialogController) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (from is PreferenceDialogController || internalTo is PreferenceDialogController) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
|
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
|
||||||
@ -557,10 +570,10 @@ class MainActivity : BaseActivity() {
|
|||||||
// Always show appbar again when changing controllers
|
// Always show appbar again when changing controllers
|
||||||
binding.appbar.setExpanded(true)
|
binding.appbar.setExpanded(true)
|
||||||
|
|
||||||
if ((from == null || from is RootController) && to !is RootController) {
|
if ((from == null || from is RootController) && internalTo !is RootController) {
|
||||||
showNav(false)
|
showNav(false)
|
||||||
}
|
}
|
||||||
if (to is RootController) {
|
if (internalTo is RootController) {
|
||||||
// Always show bottom nav again when returning to a RootController
|
// Always show bottom nav again when returning to a RootController
|
||||||
showNav(true)
|
showNav(true)
|
||||||
}
|
}
|
||||||
@ -568,8 +581,8 @@ class MainActivity : BaseActivity() {
|
|||||||
if (from is TabbedController) {
|
if (from is TabbedController) {
|
||||||
from.cleanupTabs(binding.tabs)
|
from.cleanupTabs(binding.tabs)
|
||||||
}
|
}
|
||||||
if (to is TabbedController) {
|
if (internalTo is TabbedController) {
|
||||||
if (to.configureTabs(binding.tabs)) {
|
if (internalTo.configureTabs(binding.tabs)) {
|
||||||
binding.tabs.isVisible = true
|
binding.tabs.isVisible = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -579,9 +592,9 @@ class MainActivity : BaseActivity() {
|
|||||||
if (from is FabController) {
|
if (from is FabController) {
|
||||||
from.cleanupFab(binding.fabLayout.rootFab)
|
from.cleanupFab(binding.fabLayout.rootFab)
|
||||||
}
|
}
|
||||||
if (to is FabController) {
|
if (internalTo is FabController) {
|
||||||
binding.fabLayout.rootFab.show()
|
binding.fabLayout.rootFab.show()
|
||||||
to.configureFab(binding.fabLayout.rootFab)
|
internalTo.configureFab(binding.fabLayout.rootFab)
|
||||||
} else {
|
} else {
|
||||||
binding.fabLayout.rootFab.hide()
|
binding.fabLayout.rootFab.hide()
|
||||||
}
|
}
|
||||||
@ -599,7 +612,7 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
binding.appbar.isLifted = false
|
binding.appbar.isLifted = false
|
||||||
} else {
|
} else {
|
||||||
to?.let {
|
internalTo?.let {
|
||||||
binding.appbar.isLifted = backstackLiftState.getOrElse(it.instanceId) { false }
|
binding.appbar.isLifted = backstackLiftState.getOrElse(it.instanceId) { false }
|
||||||
}
|
}
|
||||||
from?.let {
|
from?.let {
|
||||||
@ -607,10 +620,10 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.root.isLiftAppBarOnScroll = to !is NoAppBarElevationController
|
binding.root.isLiftAppBarOnScroll = internalTo !is NoAppBarElevationController
|
||||||
|
|
||||||
binding.appbar.isTransparentWhenNotLifted = to is MangaController
|
binding.appbar.isTransparentWhenNotLifted = internalTo is MangaController
|
||||||
binding.controllerContainer.overlapHeader = to is MangaController
|
binding.controllerContainer.overlapHeader = internalTo is MangaController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user