Tabs: Don't explicitly set text color in the text (#8365)

The container already provides color option for both states

(cherry picked from commit 156191af4454d756e51e331f67cba7e19efbbb38)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/components/Tabs.kt
#	app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt
#	app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt
This commit is contained in:
Ivan Iskandar 2022-10-30 23:04:46 +07:00 committed by Jobobby04
parent 2dc3569eee
commit c505f31ad3
4 changed files with 19 additions and 27 deletions

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Tab import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow import androidx.compose.material3.TabRow
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -80,9 +81,8 @@ fun TabbedScreen(
Tab( Tab(
selected = state.currentPage == index, selected = state.currentPage == index,
onClick = { scope.launch { state.animateScrollToPage(index) } }, onClick = { scope.launch { state.animateScrollToPage(index) } },
text = { text = { TabText(text = stringResource(tab.titleRes), badgeCount = tab.badgeNumber) },
TabText(stringResource(tab.titleRes), tab.badgeNumber, state.currentPage == index) unselectedContentColor = MaterialTheme.colorScheme.onSurface,
},
) )
} }
} }

View File

@ -31,7 +31,6 @@ fun TabIndicator(currentTabPosition: TabPosition) {
fun TabText( fun TabText(
text: String, text: String,
badgeCount: Int? = null, badgeCount: Int? = null,
isCurrentPage: Boolean,
) { ) {
val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f
@ -40,7 +39,6 @@ fun TabText(
) { ) {
Text( Text(
text = text, text = text,
color = if (isCurrentPage) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground,
// SY --> // SY -->
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,

View File

@ -77,12 +77,13 @@ fun LibraryContent(
if (isLibraryEmpty.not() && showPageTabs && categories.size > 1) { if (isLibraryEmpty.not() && showPageTabs && categories.size > 1) {
LibraryTabs( LibraryTabs(
state = pagerState,
categories = categories, categories = categories,
currentPageIndex = pagerState.currentPage.coerceAtMost(categories.lastIndex),
showMangaCount = showMangaCount, showMangaCount = showMangaCount,
getNumberOfMangaForCategory = getNumberOfMangaForCategory, getNumberOfMangaForCategory = getNumberOfMangaForCategory,
isDownloadOnly = isDownloadOnly, isDownloadOnly = isDownloadOnly,
isIncognitoMode = isIncognitoMode, isIncognitoMode = isIncognitoMode,
onTabItemClick = { scope.launch { pagerState.animateScrollToPage(it) } },
// SY --> // SY -->
getCategoryName = { category, name -> getCategoryName = { category, name ->
val context = LocalContext.current val context = LocalContext.current

View File

@ -1,65 +1,58 @@
package eu.kanade.presentation.library.components package eu.kanade.presentation.library.components
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ScrollableTabRow import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab import androidx.compose.material3.Tab
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.State import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.Category
import eu.kanade.presentation.category.visualName import eu.kanade.presentation.category.visualName
import eu.kanade.presentation.components.AppStateBanners import eu.kanade.presentation.components.AppStateBanners
import eu.kanade.presentation.components.Divider import eu.kanade.presentation.components.Divider
import eu.kanade.presentation.components.PagerState
import eu.kanade.presentation.components.TabIndicator import eu.kanade.presentation.components.TabIndicator
import eu.kanade.presentation.components.TabText import eu.kanade.presentation.components.TabText
import kotlinx.coroutines.launch
@Composable @Composable
fun LibraryTabs( fun LibraryTabs(
state: PagerState,
categories: List<Category>, categories: List<Category>,
currentPageIndex: Int,
showMangaCount: Boolean, showMangaCount: Boolean,
isDownloadOnly: Boolean, isDownloadOnly: Boolean,
isIncognitoMode: Boolean, isIncognitoMode: Boolean,
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>, getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
onTabItemClick: (Int) -> Unit,
// SY --> // SY -->
getCategoryName: @Composable (Category, String) -> String, getCategoryName: @Composable (Category, String) -> String,
// SY <-- // SY <--
) { ) {
val scope = rememberCoroutineScope()
Column { Column {
ScrollableTabRow( ScrollableTabRow(
selectedTabIndex = state.currentPage.coerceAtMost(categories.lastIndex), selectedTabIndex = currentPageIndex,
edgePadding = 0.dp, edgePadding = 0.dp,
indicator = { TabIndicator(it[state.currentPage.coerceAtMost(categories.lastIndex)]) }, indicator = { TabIndicator(it[currentPageIndex]) },
// TODO: use default when width is fixed upstream // TODO: use default when width is fixed upstream
// https://issuetracker.google.com/issues/242879624 // https://issuetracker.google.com/issues/242879624
divider = {}, divider = {},
) { ) {
categories.forEachIndexed { index, category -> categories.forEachIndexed { index, category ->
val count by if (showMangaCount) {
getNumberOfMangaForCategory(category.id)
} else {
remember { mutableStateOf<Int?>(null) }
}
Tab( Tab(
selected = state.currentPage == index, selected = currentPageIndex == index,
onClick = { scope.launch { state.animateScrollToPage(index) } }, onClick = { onTabItemClick(index) },
text = { text = {
TabText( TabText(
// SY --> // SY -->
text = getCategoryName(category, category.visualName), text = getCategoryName(category, category.visualName),
// SY <-- // SY <--,
count, badgeCount = if (showMangaCount) {
state.currentPage == index, getNumberOfMangaForCategory(category.id)
} else {
null
}?.value,
) )
}, },
unselectedContentColor = MaterialTheme.colorScheme.onSurface,
) )
} }
} }