From 075e7c000a3e466cf2574d216b0842a68908dc7b Mon Sep 17 00:00:00 2001 From: Karan Sharma <55722391+ksharma-xyz@users.noreply.github.com> Date: Thu, 6 Feb 2025 16:07:17 +1100 Subject: [PATCH 1/2] Text should repect style of LocalTextStyle composition local provider --- .../kotlin/xyz/ksharma/krail/taj/components/Text.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt index 65204aeb..c4a58f28 100644 --- a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt +++ b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt @@ -26,7 +26,6 @@ fun Text( textAlign: TextAlign = TextAlign.Start, maxLines: Int = Int.MAX_VALUE, overflow: TextOverflow = if (maxLines == Int.MAX_VALUE) TextOverflow.Clip else TextOverflow.Ellipsis, - fontFamily: FontFamily? = null, onTextLayout: ((TextLayoutResult) -> Unit)? = null, ) { Text( @@ -37,7 +36,6 @@ fun Text( textAlign = textAlign, maxLines = maxLines, overflow = overflow, - fontFamily = fontFamily, onTextLayout = onTextLayout, ) } @@ -55,9 +53,11 @@ fun Text( onTextLayout: ((TextLayoutResult) -> Unit)? = null, ) { val contentAlpha = LocalContentAlpha.current + val textStyle = style.merge(LocalTextStyle.current) + BasicText( text = text, - style = style.merge( + style = textStyle.copy( color = color?.copy(alpha = contentAlpha) ?: LocalTextColor.current.copy(alpha = contentAlpha), textAlign = textAlign, From 606e8466eb5db696b1a106a7f2cc7b89f07e47b1 Mon Sep 17 00:00:00 2001 From: Karan Sharma <55722391+ksharma-xyz@users.noreply.github.com> Date: Thu, 6 Feb 2025 16:13:28 +1100 Subject: [PATCH 2/2] proper usage of color. use composition local, if it is not specified, then use the color provided otherwise fallback on the onSurface --- .../kotlin/xyz/ksharma/krail/taj/components/Text.kt | 5 +++-- .../kotlin/xyz/ksharma/krail/taj/theme/KrailTypography.kt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt index c4a58f28..2a6b99ad 100644 --- a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt +++ b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/components/Text.kt @@ -54,12 +54,13 @@ fun Text( ) { val contentAlpha = LocalContentAlpha.current val textStyle = style.merge(LocalTextStyle.current) + val textColor: Color = LocalTextColor.current + .takeIf { it != Color.Unspecified } ?: color ?: KrailTheme.colors.onSurface BasicText( text = text, style = textStyle.copy( - color = color?.copy(alpha = contentAlpha) - ?: LocalTextColor.current.copy(alpha = contentAlpha), + color = textColor.copy(alpha = contentAlpha), textAlign = textAlign, fontFamily = fontFamily, ), diff --git a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/theme/KrailTypography.kt b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/theme/KrailTypography.kt index d4077c63..008d58c1 100644 --- a/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/theme/KrailTypography.kt +++ b/taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/theme/KrailTypography.kt @@ -2,6 +2,7 @@ package xyz.ksharma.krail.taj.theme import androidx.compose.runtime.Immutable import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight