Merge pull request #1427 from fansangg/fix/theme-switch

fix:切换主题风格后会 “自动跳转最近阅读”

@fansangg
This commit is contained in:
Kudomaga authored and GitHub committed 2026-06-14 13:28:04 +08:00
commit 7c9b87a3c4
1 file changed
+8 -1
@@ -20,6 +20,7 @@ import androidx.compose.animation.scaleOut
import androidx.compose.animation.togetherWith import androidx.compose.animation.togetherWith
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.snapshotFlow
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
@@ -148,6 +149,7 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
private val viewModel by viewModel<MainViewModel>() private val viewModel by viewModel<MainViewModel>()
private val routeEvents = MutableSharedFlow<NavKey>(extraBufferCapacity = 1) private val routeEvents = MutableSharedFlow<NavKey>(extraBufferCapacity = 1)
private var bookInfoVariableSetter: ((String, String?) -> Unit)? = null private var bookInfoVariableSetter: ((String, String?) -> Unit)? = null
private var shouldApplyDefaultToRead = true
private var restoredReadBookRoute: MainRouteReadBook? = null private var restoredReadBookRoute: MainRouteReadBook? = null
private var latestBackStack: List<NavKey> = emptyList() private var latestBackStack: List<NavKey> = emptyList()
internal var activeReadBookInputHandler: ReadBookInputHandler? = null internal var activeReadBookInputHandler: ReadBookInputHandler? = null
@@ -155,6 +157,7 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen() installSplashScreen()
shouldApplyDefaultToRead = savedInstanceState == null
restoredReadBookRoute = savedInstanceState?.restoreReadBookRoute() restoredReadBookRoute = savedInstanceState?.restoreReadBookRoute()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -210,7 +213,7 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
!hasExplicitStartRoute && restoredReadBookRoute != null -> { !hasExplicitStartRoute && restoredReadBookRoute != null -> {
arrayOf(MainRouteHome, restoredReadBookRoute!!) arrayOf(MainRouteHome, restoredReadBookRoute!!)
} }
OtherConfig.defaultToRead && resolved == MainRouteHome -> { shouldApplyDefaultToRead && OtherConfig.defaultToRead && resolved == MainRouteHome -> {
arrayOf(MainRouteHome, MainRouteReadBook()) arrayOf(MainRouteHome, MainRouteReadBook())
} }
else -> { else -> {
@@ -221,6 +224,10 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
latestBackStack = startRoutes.toList() latestBackStack = startRoutes.toList()
val backStack = rememberNavBackStack(*startRoutes) val backStack = rememberNavBackStack(*startRoutes)
SideEffect {
shouldApplyDefaultToRead = false
}
LaunchedEffect(backStack) { LaunchedEffect(backStack) {
routeEvents.collect { route -> routeEvents.collect { route ->
MainNavigator.navigateToRoute(backStack, route) MainNavigator.navigateToRoute(backStack, route)