[优化] 修复目录刷新

This commit is contained in:
HapeLee
2026-03-06 02:12:58 +08:00
parent 1d828837fb
commit d4861e9508
@@ -110,6 +110,7 @@ import io.legado.app.ui.widget.components.lazylist.FastScrollLazyColumn
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
import io.legado.app.ui.widget.components.topbar.DynamicTopAppBar import io.legado.app.ui.widget.components.topbar.DynamicTopAppBar
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel import org.koin.androidx.compose.koinViewModel
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@@ -229,10 +230,12 @@ fun TocScreen(
var hasAutoScrolled by rememberSaveable { mutableStateOf(false) } var hasAutoScrolled by rememberSaveable { mutableStateOf(false) }
LaunchedEffect(state.items) { LaunchedEffect(state.items, book) {
if (!hasAutoScrolled && state.items.isNotEmpty()) { if (!hasAutoScrolled && state.items.isNotEmpty() && book != null) {
val targetIndex = state.items.indexOfFirst { it.isDur } val durIndex = book?.durChapterIndex ?: -1
val targetIndex = state.items.indexOfFirst { it.id == durIndex || it.isDur }
if (targetIndex != -1) { if (targetIndex != -1) {
delay(100)
listState.scrollToItem( listState.scrollToItem(
index = targetIndex, index = targetIndex,
scrollOffset = -offset scrollOffset = -offset