From 5c4a24f15e807eeb0996ecc63fb692c2239aacee Mon Sep 17 00:00:00 2001 From: another-simple-pixel Date: Mon, 18 May 2026 04:12:05 -0700 Subject: [PATCH] Section / Theme: extract sectionCardColor() helper Three SectionView overloads were each computing the same cardColor inline: if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White else MaterialTheme.colors.background.mixWith(...). DRY violation paired with the canvasColorForCurrentTheme() helper that already covers the canvas side of the same theme split. Add a sectionCardColor() function in Theme.kt and collapse the 3 inline formulas to one call. --- .../kotlin/chat/simplex/common/ui/theme/Theme.kt | 9 +++++++++ .../kotlin/chat/simplex/common/views/helpers/Section.kt | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt index 13969a923d..b70746db86 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/ui/theme/Theme.kt @@ -613,6 +613,15 @@ fun canvasColorForCurrentTheme(): Color { } } +// Card background color for SectionView. LIGHT: pure white (raised above the +// off-white canvas). DARK/BLACK/SIMPLEX: founder's mixWith formula (lifts cards +// above palette bg using onBackground tint). +fun sectionCardColor(): Color { + val theme = CurrentColors.value + return if (theme.base == DefaultTheme.LIGHT) Color.White + else theme.colors.background.mixWith(theme.colors.onBackground, 0.95f) +} + fun Modifier.themedBackground(baseTheme: DefaultTheme = CurrentColors.value.base, bgLayerSize: MutableState?, bgLayer: GraphicsLayer?/*, shape: Shape = RectangleShape*/): Modifier { return drawBehind { copyBackgroundToAppBar(bgLayerSize, bgLayer) { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt index 7e38291429..c8b0dc70ec 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt @@ -46,8 +46,7 @@ private fun Modifier.sectionItemDivider(): Modifier { @Composable fun SectionView(title: String? = null, contentPadding: PaddingValues = PaddingValues(), headerBottomPadding: Dp = 8.dp, content: (@Composable ColumnScope.() -> Unit)) { - val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White - else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f) + val cardColor = sectionCardColor() Column { if (title != null) { Text( @@ -77,8 +76,7 @@ fun SectionView( padding: PaddingValues = PaddingValues(), content: (@Composable ColumnScope.() -> Unit) ) { - val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White - else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f) + val cardColor = sectionCardColor() Column { val iconSize = with(LocalDensity.current) { 21.sp.toDp() } Row(Modifier.padding(start = DEFAULT_PADDING + DEFAULT_PADDING_HALF, bottom = 5.dp), verticalAlignment = Alignment.CenterVertically) { @@ -101,8 +99,7 @@ fun SectionView( @Composable fun SectionViewWithButton(title: String? = null, titleButton: (@Composable () -> Unit)?, contentPadding: PaddingValues = PaddingValues(), headerBottomPadding: Dp = 8.dp, content: (@Composable ColumnScope.() -> Unit)) { - val cardColor = if (CurrentColors.value.base == DefaultTheme.LIGHT) Color.White - else MaterialTheme.colors.background.mixWith(MaterialTheme.colors.onBackground, 0.95f) + val cardColor = sectionCardColor() Column { if (title != null || titleButton != null) { Row(modifier = Modifier.padding(start = DEFAULT_PADDING + DEFAULT_PADDING_HALF, end = DEFAULT_PADDING + DEFAULT_PADDING_HALF, bottom = headerBottomPadding).fillMaxWidth()) {