Optimize navigation back stack

Fix topjohnwu#4333

Co-authored-by: LoveSy <shana@zju.edu.cn>
This commit is contained in:
canyie 2022-01-20 17:13:16 +08:00 committed by John Wu
parent 1f5992f2c2
commit b0fba6ce5b
4 changed files with 9 additions and 8 deletions

View File

@ -98,8 +98,8 @@ abstract class BaseViewModel(
_viewEvents.postValue(this)
}
fun NavDirections.navigate() {
_viewEvents.postValue(NavigationEvent(this))
fun NavDirections.navigate(pop: Boolean = false) {
_viewEvents.postValue(NavigationEvent(this, pop))
}
}

View File

@ -62,10 +62,12 @@ class MagiskInstallFileEvent(
}
class NavigationEvent(
private val directions: NavDirections
private val directions: NavDirections,
private val pop: Boolean
) : ViewEvent(), ActivityExecutor {
override fun invoke(activity: BaseUIActivity<*, *>) {
(activity as? BaseUIActivity<*, *>)?.apply {
if (pop) navigation?.popBackStack()
directions.navigate()
}
}

View File

@ -84,9 +84,9 @@ class InstallViewModel(
fun install() {
when (method) {
R.id.method_patch -> FlashFragment.patch(data!!).navigate()
R.id.method_direct -> FlashFragment.flash(false).navigate()
R.id.method_inactive_slot -> FlashFragment.flash(true).navigate()
R.id.method_patch -> FlashFragment.patch(data!!).navigate(true)
R.id.method_direct -> FlashFragment.flash(false).navigate(true)
R.id.method_inactive_slot -> FlashFragment.flash(true).navigate(true)
else -> error("Unknown value")
}
state = State.LOADING

View File

@ -150,7 +150,6 @@
app:enterAnim="@anim/fragment_enter"
app:exitAnim="@anim/fragment_exit"
app:popEnterAnim="@anim/fragment_enter_pop"
app:popExitAnim="@anim/fragment_exit_pop"
app:popUpTo="@id/homeFragment" />
app:popExitAnim="@anim/fragment_exit_pop" />
</navigation>