fix: Apply correct content color to list items

This commit is contained in:
Artem Chepurnoy 2024-04-10 11:12:47 +03:00
parent 30db360ef1
commit 3fc4ec3f03
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
2 changed files with 26 additions and 2 deletions

View File

@ -38,6 +38,7 @@ import androidx.compose.material3.LocalMinimumInteractiveComponentEnforcement
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
@ -620,6 +621,10 @@ private enum class Try {
fun FlatItemLayout2(
modifier: Modifier = Modifier,
backgroundColor: Color,
contentColor: Color = backgroundColor
.takeIf { it.isSpecified }
?.let { contentColorFor(it) }
?: LocalContentColor.current,
content: @Composable ColumnScope.() -> Unit,
leading: (@Composable RowScope.() -> Unit)? = null,
trailing: (@Composable RowScope.() -> Unit)? = null,
@ -670,7 +675,7 @@ fun FlatItemLayout2(
verticalAlignment = Alignment.CenterVertically,
) {
CompositionLocalProvider(
LocalContentColor provides LocalContentColor.current
LocalContentColor provides contentColor
.let { color ->
if (enabled) {
color

View File

@ -68,6 +68,7 @@ import com.artemchep.keyguard.feature.home.vault.component.localSurfaceColorAtEl
import com.artemchep.keyguard.feature.home.vault.component.surfaceColorAtElevationSemi
import com.artemchep.keyguard.feature.home.vault.model.VaultItemIcon
import com.artemchep.keyguard.ui.surface.LocalSurfaceColor
import com.artemchep.keyguard.ui.surface.ProvideSurfaceColor
import com.artemchep.keyguard.ui.theme.combineAlpha
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.toPersistentList
@ -416,6 +417,10 @@ fun FlatItemLayout(
contentPadding: PaddingValues = defaultContentPadding,
elevation: Dp = 0.dp,
backgroundColor: Color = Color.Unspecified,
contentColor: Color = backgroundColor
.takeIf { it.isSpecified }
?.let { contentColorFor(it) }
?: LocalContentColor.current,
content: @Composable ColumnScope.() -> Unit,
actions: List<FlatItemAction> = emptyList(),
leading: (@Composable RowScope.() -> Unit)? = null,
@ -424,10 +429,11 @@ fun FlatItemLayout(
onLongClick: (() -> Unit)? = null,
enabled: Boolean = onClick != null,
) {
Column(
ContentColorColumn(
modifier = modifier
.fillMaxWidth()
.padding(paddingValues),
color = contentColor,
) {
val backgroundModifier = kotlin.run {
// Check if there's actually a background color
@ -566,6 +572,19 @@ fun FlatItemLayout(
}
}
@Composable
private fun ContentColorColumn(
modifier: Modifier = Modifier,
color: Color,
content: @Composable ColumnScope.() -> Unit,
) = Column(modifier = modifier) {
CompositionLocalProvider(
LocalContentColor provides color,
) {
content()
}
}
@Composable
fun RowScope.FlatItemActionContent(
action: FlatItemAction,