From e262452648e51cba2fefdbba574aaf016f770b0a Mon Sep 17 00:00:00 2001 From: halilozercan Date: Fri, 6 Aug 2021 15:26:03 +0300 Subject: [PATCH] Fix Dark Mode coloring issue in RichTextString and Table Borders - Default to S01 for Maven Central uploads --- build.gradle | 8 +++++ .../zachklipp/richtext/ui/RichTextLocals.kt | 29 ++++++++++++++++++- .../java/com/zachklipp/richtext/ui/Table.kt | 6 ++-- .../com/zachklipp/richtext/ui/string/Text.kt | 6 ++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 2fcf3af1..721c45a6 100644 --- a/build.gradle +++ b/build.gradle @@ -120,6 +120,14 @@ def isRunningFromIde() { return project.properties["android.injected.invoked.from.ide"] == "true" } +allprojects { + plugins.withId("com.vanniktech.maven.publish") { + mavenPublish { + sonatypeHost = "S01" + } + } +} + subprojects { repositories { google() diff --git a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/RichTextLocals.kt b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/RichTextLocals.kt index 31a4ab11..ac698ade 100644 --- a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/RichTextLocals.kt +++ b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/RichTextLocals.kt @@ -1,11 +1,13 @@ package com.zachklipp.richtext.ui import androidx.compose.foundation.text.BasicText +import androidx.compose.foundation.text.InlineTextContent import androidx.compose.runtime.Composable import androidx.compose.runtime.compositionLocalOf import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.takeOrElse +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextOverflow @@ -74,4 +76,29 @@ internal fun RichTextScope.Text( softWrap = softWrap, maxLines = maxLines ) -} \ No newline at end of file +} + +@Composable +internal fun RichTextScope.Text( + text: AnnotatedString, + modifier: Modifier = Modifier, + onTextLayout: (TextLayoutResult) -> Unit = {}, + overflow: TextOverflow = TextOverflow.Clip, + softWrap: Boolean = true, + maxLines: Int = Int.MAX_VALUE, + inlineContent: Map = mapOf(), +) { + val textColor = currentTextStyle.color.takeOrElse { currentContentColor } + val style = currentTextStyle.copy(color = textColor) + + BasicText( + text = text, + modifier = modifier, + style = style, + onTextLayout = onTextLayout, + overflow = overflow, + softWrap = softWrap, + maxLines = maxLines, + inlineContent = inlineContent + ) +} diff --git a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/Table.kt b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/Table.kt index 1a66875b..2d5954b8 100644 --- a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/Table.kt +++ b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/Table.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight @@ -43,7 +44,7 @@ public data class TableStyle( private val DefaultTableHeaderTextStyle = TextStyle(fontWeight = FontWeight.Bold) private val DefaultCellPadding = 8.sp -private val DefaultBorderColor = Color.Black +private val DefaultBorderColor = Color.Unspecified private const val DefaultBorderStrokeWidth = 1f internal fun TableStyle.resolveDefaults() = TableStyle( @@ -93,6 +94,7 @@ public fun RichTextScope.Table( bodyRows: RichTextTableRowScope.() -> Unit ) { val tableStyle = currentRichTextStyle.resolveDefaults().tableStyle!! + val contentColor = currentContentColor val header = remember(headerRow) { headerRow?.let { RowBuilder().apply(headerRow).row } } @@ -153,7 +155,7 @@ public fun RichTextScope.Table( Modifier.drawTableBorders( rowOffsets = layoutResult.rowOffsets, columnOffsets = layoutResult.columnOffsets, - borderColor = tableStyle.borderColor!!, + borderColor = tableStyle.borderColor!!.takeOrElse { contentColor }, borderStrokeWidth = tableStyle.borderStrokeWidth ) }, diff --git a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/string/Text.kt b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/string/Text.kt index d3c6fcdc..c1459b08 100644 --- a/richtext-ui/src/main/java/com/zachklipp/richtext/ui/string/Text.kt +++ b/richtext-ui/src/main/java/com/zachklipp/richtext/ui/string/Text.kt @@ -1,7 +1,6 @@ package com.zachklipp.richtext.ui.string import androidx.compose.foundation.gestures.detectTapGestures -import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue @@ -17,9 +16,9 @@ import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Constraints import com.zachklipp.richtext.ui.RichTextScope +import com.zachklipp.richtext.ui.Text import com.zachklipp.richtext.ui.currentContentColor import com.zachklipp.richtext.ui.currentRichTextStyle -import com.zachklipp.richtext.ui.currentTextStyle import com.zachklipp.richtext.ui.string.RichTextString.Format import com.zachklipp.richtext.ui.string.RichTextString.Format.Bold import com.zachklipp.richtext.ui.string.RichTextString.Format.Link @@ -91,13 +90,12 @@ public fun RichTextScope.Text( Layout( modifier = modifier.then(pressIndicator), content = { - BasicText( + Text( text = hack, onTextLayout = { result -> layoutResult.value = result onTextLayout(result) }, - style = currentTextStyle, inlineContent = inlineTextContents ) }