Here lies "currentTab was used multiple times"

Fixes #282
This commit is contained in:
AntsyLich 2024-10-29 21:15:14 +06:00
parent 38d5fc9160
commit 371c1432e2
No known key found for this signature in database
8 changed files with 44 additions and 27 deletions

View file

@ -11,6 +11,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- `Other` - for technical stuff.
## [Unreleased]
### Fixed
- Fixed "currentTab was used multiple times"
## [v0.17.0] - 2024-10-26
### Added

View file

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryTabRow
@ -14,7 +15,6 @@ import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Tab
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
@ -33,20 +33,13 @@ import tachiyomi.presentation.core.i18n.stringResource
fun TabbedScreen(
titleRes: StringResource,
tabs: ImmutableList<TabContent>,
startIndex: Int? = null,
state: PagerState = rememberPagerState { tabs.size },
searchQuery: String? = null,
onChangeSearchQuery: (String?) -> Unit = {},
) {
val scope = rememberCoroutineScope()
val state = rememberPagerState { tabs.size }
val snackbarHostState = remember { SnackbarHostState() }
LaunchedEffect(startIndex) {
if (startIndex != null) {
state.scrollToPage(startIndex)
}
}
Scaffold(
topBar = {
val tab = tabs[state.currentPage]

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.browse
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
@ -22,12 +23,14 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchScreen
import eu.kanade.tachiyomi.ui.browse.source.sourcesTab
import eu.kanade.tachiyomi.ui.main.MainActivity
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
data class BrowseTab(
private val toExtensions: Boolean = false,
) : Tab {
data object BrowseTab : Tab {
override val options: TabOptions
@Composable
@ -45,6 +48,12 @@ data class BrowseTab(
navigator.push(GlobalSearchScreen())
}
private val switchToExtensionTabChannel = Channel<Unit>(1, BufferOverflow.DROP_OLDEST)
fun showExtension() {
switchToExtensionTabChannel.trySend(Unit)
}
@Composable
override fun Content() {
val context = LocalContext.current
@ -53,17 +62,25 @@ data class BrowseTab(
val extensionsScreenModel = rememberScreenModel { ExtensionsScreenModel() }
val extensionsState by extensionsScreenModel.state.collectAsState()
TabbedScreen(
titleRes = MR.strings.browse,
tabs = persistentListOf(
val tabs = persistentListOf(
sourcesTab(),
extensionsTab(extensionsScreenModel),
migrateSourceTab(),
),
startIndex = 1.takeIf { toExtensions },
)
val state = rememberPagerState { tabs.size }
TabbedScreen(
titleRes = MR.strings.browse,
tabs = tabs,
state = state,
searchQuery = extensionsState.searchQuery,
onChangeSearchQuery = extensionsScreenModel::search,
)
LaunchedEffect(Unit) {
switchToExtensionTabChannel.receiveAsFlow()
.collectLatest { state.scrollToPage(1) }
}
LaunchedEffect(Unit) {
(context as? MainActivity)?.ready = true

View file

@ -32,7 +32,7 @@ import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
object HistoryTab : Tab {
data object HistoryTab : Tab {
private val snackbarHostState = SnackbarHostState()

View file

@ -69,11 +69,11 @@ object HomeScreen : Screen() {
private const val TAB_FADE_DURATION = 200
private const val TAB_NAVIGATOR_KEY = "HomeTabs"
private val tabs = listOf(
private val TABS = listOf(
LibraryTab,
UpdatesTab,
HistoryTab,
BrowseTab(),
BrowseTab,
MoreTab,
)
@ -90,7 +90,7 @@ object HomeScreen : Screen() {
startBar = {
if (isTabletUi()) {
NavigationRail {
tabs.fastForEach {
TABS.fastForEach {
NavigationRailItem(it)
}
}
@ -107,7 +107,7 @@ object HomeScreen : Screen() {
exit = shrinkVertically(),
) {
NavigationBar {
tabs.fastForEach {
TABS.fastForEach {
NavigationBarItem(it)
}
}
@ -159,7 +159,12 @@ object HomeScreen : Screen() {
is Tab.Library -> LibraryTab
Tab.Updates -> UpdatesTab
Tab.History -> HistoryTab
is Tab.Browse -> BrowseTab(it.toExtensions)
is Tab.Browse -> {
if (it.toExtensions) {
BrowseTab.showExtension()
}
BrowseTab
}
is Tab.More -> MoreTab
}

View file

@ -61,7 +61,7 @@ import tachiyomi.presentation.core.screens.EmptyScreenAction
import tachiyomi.presentation.core.screens.LoadingScreen
import tachiyomi.source.local.isLocal
object LibraryTab : Tab {
data object LibraryTab : Tab {
override val options: TabOptions
@Composable

View file

@ -38,7 +38,7 @@ import tachiyomi.presentation.core.i18n.stringResource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
object MoreTab : Tab {
data object MoreTab : Tab {
override val options: TabOptions
@Composable

View file

@ -31,7 +31,7 @@ import tachiyomi.core.common.i18n.stringResource
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
object UpdatesTab : Tab {
data object UpdatesTab : Tab {
override val options: TabOptions
@Composable