Skip to content

Commit

Permalink
Fix Dark Mode coloring issue in RichTextString and Table Borders
Browse files Browse the repository at this point in the history
- Default to S01 for Maven Central uploads
  • Loading branch information
halilozercan committed Aug 6, 2021
1 parent 99ab621 commit e262452
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -74,4 +76,29 @@ internal fun RichTextScope.Text(
softWrap = softWrap,
maxLines = maxLines
)
}
}

@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<String, InlineTextContent> = 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
)
}
6 changes: 4 additions & 2 deletions richtext-ui/src/main/java/com/zachklipp/richtext/ui/Table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
}
Expand Down

0 comments on commit e262452

Please sign in to comment.