Skip to content

Commit 3fc4ec3

Browse files
committedApr 10, 2024
fix: Apply correct content color to list items
1 parent 30db360 commit 3fc4ec3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

‎common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/VaultListItem.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import androidx.compose.material3.LocalMinimumInteractiveComponentEnforcement
3838
import androidx.compose.material3.MaterialTheme
3939
import androidx.compose.material3.ProvideTextStyle
4040
import androidx.compose.material3.Text
41+
import androidx.compose.material3.contentColorFor
4142
import androidx.compose.material3.minimumInteractiveComponentSize
4243
import androidx.compose.runtime.Composable
4344
import androidx.compose.runtime.CompositionLocalProvider
@@ -620,6 +621,10 @@ private enum class Try {
620621
fun FlatItemLayout2(
621622
modifier: Modifier = Modifier,
622623
backgroundColor: Color,
624+
contentColor: Color = backgroundColor
625+
.takeIf { it.isSpecified }
626+
?.let { contentColorFor(it) }
627+
?: LocalContentColor.current,
623628
content: @Composable ColumnScope.() -> Unit,
624629
leading: (@Composable RowScope.() -> Unit)? = null,
625630
trailing: (@Composable RowScope.() -> Unit)? = null,
@@ -670,7 +675,7 @@ fun FlatItemLayout2(
670675
verticalAlignment = Alignment.CenterVertically,
671676
) {
672677
CompositionLocalProvider(
673-
LocalContentColor provides LocalContentColor.current
678+
LocalContentColor provides contentColor
674679
.let { color ->
675680
if (enabled) {
676681
color

‎common/src/commonMain/kotlin/com/artemchep/keyguard/ui/PasswordFilterItem.kt

+20-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import com.artemchep.keyguard.feature.home.vault.component.localSurfaceColorAtEl
6868
import com.artemchep.keyguard.feature.home.vault.component.surfaceColorAtElevationSemi
6969
import com.artemchep.keyguard.feature.home.vault.model.VaultItemIcon
7070
import com.artemchep.keyguard.ui.surface.LocalSurfaceColor
71+
import com.artemchep.keyguard.ui.surface.ProvideSurfaceColor
7172
import com.artemchep.keyguard.ui.theme.combineAlpha
7273
import kotlinx.collections.immutable.PersistentList
7374
import kotlinx.collections.immutable.toPersistentList
@@ -416,6 +417,10 @@ fun FlatItemLayout(
416417
contentPadding: PaddingValues = defaultContentPadding,
417418
elevation: Dp = 0.dp,
418419
backgroundColor: Color = Color.Unspecified,
420+
contentColor: Color = backgroundColor
421+
.takeIf { it.isSpecified }
422+
?.let { contentColorFor(it) }
423+
?: LocalContentColor.current,
419424
content: @Composable ColumnScope.() -> Unit,
420425
actions: List<FlatItemAction> = emptyList(),
421426
leading: (@Composable RowScope.() -> Unit)? = null,
@@ -424,10 +429,11 @@ fun FlatItemLayout(
424429
onLongClick: (() -> Unit)? = null,
425430
enabled: Boolean = onClick != null,
426431
) {
427-
Column(
432+
ContentColorColumn(
428433
modifier = modifier
429434
.fillMaxWidth()
430435
.padding(paddingValues),
436+
color = contentColor,
431437
) {
432438
val backgroundModifier = kotlin.run {
433439
// Check if there's actually a background color
@@ -566,6 +572,19 @@ fun FlatItemLayout(
566572
}
567573
}
568574

575+
@Composable
576+
private fun ContentColorColumn(
577+
modifier: Modifier = Modifier,
578+
color: Color,
579+
content: @Composable ColumnScope.() -> Unit,
580+
) = Column(modifier = modifier) {
581+
CompositionLocalProvider(
582+
LocalContentColor provides color,
583+
) {
584+
content()
585+
}
586+
}
587+
569588
@Composable
570589
fun RowScope.FlatItemActionContent(
571590
action: FlatItemAction,

0 commit comments

Comments
 (0)