fix: 修复全文搜索等界面多次点击返回导致退出上级界面
This commit is contained in:
@@ -25,8 +25,10 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
|
||||
import androidx.navigation3.runtime.NavKey
|
||||
import androidx.navigation3.runtime.rememberNavBackStack
|
||||
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
|
||||
import androidx.navigation3.scene.SinglePaneSceneStrategy
|
||||
import androidx.navigation3.ui.NavDisplay
|
||||
import io.legado.app.BuildConfig
|
||||
@@ -236,12 +238,19 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
||||
|
||||
LaunchedEffect(backStack) {
|
||||
snapshotFlow { backStack.toList() }
|
||||
.collect { latestBackStack = it }
|
||||
.collect {
|
||||
latestBackStack = it
|
||||
MainNavigator.onBackStackChanged()
|
||||
}
|
||||
}
|
||||
|
||||
SharedTransitionLayout {
|
||||
NavDisplay(
|
||||
backStack = backStack,
|
||||
entryDecorators = listOf(
|
||||
rememberSaveableStateHolderNavEntryDecorator(),
|
||||
rememberViewModelStoreNavEntryDecorator(),
|
||||
),
|
||||
sceneStrategies = listOf(SinglePaneSceneStrategy()),
|
||||
transitionSpec = {
|
||||
(slideIntoContainer(
|
||||
|
||||
@@ -8,6 +8,8 @@ import io.legado.app.ui.rss.read.MainRouteRssRead
|
||||
|
||||
object MainNavigator {
|
||||
|
||||
private var backNavigationInProgress = false
|
||||
|
||||
fun navigateToRoute(backStack: MutableList<NavKey>, route: NavKey) {
|
||||
val currentRoute = backStack.lastOrNull()
|
||||
if (currentRoute == route) return
|
||||
@@ -181,6 +183,10 @@ object MainNavigator {
|
||||
}
|
||||
|
||||
fun navigateBack(activity: Activity, backStack: MutableList<NavKey>) {
|
||||
if (backNavigationInProgress) {
|
||||
return
|
||||
}
|
||||
backNavigationInProgress = true
|
||||
if (backStack.size > 1) {
|
||||
backStack.removeLastOrNull()
|
||||
} else {
|
||||
@@ -188,6 +194,10 @@ object MainNavigator {
|
||||
}
|
||||
}
|
||||
|
||||
fun onBackStackChanged() {
|
||||
backNavigationInProgress = false
|
||||
}
|
||||
|
||||
fun resolveStartRoute(intent: Intent?): NavKey {
|
||||
val route = intent?.getStringExtra(MainIntent.EXTRA_START_ROUTE)
|
||||
resolveRssStartRoute(route, intent)?.let { return it }
|
||||
|
||||
Reference in New Issue
Block a user