Skip to content

Commit

Permalink
Remove material1 LocalContentColor. (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Feb 11, 2024
1 parent c8d83e0 commit a935664
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import android.widget.TextView
import androidx.annotation.FontRes
import androidx.annotation.IdRes
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -25,7 +23,6 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.res.ResourcesCompat
import coil.imageLoader
Expand Down Expand Up @@ -161,8 +158,6 @@ object MarkdownHelper {
onLongClick: ((View) -> Boolean)? = null,
style: TextStyle = MaterialTheme.typography.bodyLarge,
) {
val defaultColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)

BoxWithConstraints {
val canvasWidthMaybe = with(LocalDensity.current) { maxWidth.toPx() }.toInt()
val textSizeMaybe = with(LocalDensity.current) { style.fontSize.toPx() }
Expand All @@ -172,8 +167,6 @@ object MarkdownHelper {
createTextView(
context = ctx,
color = color,
defaultColor = defaultColor,
fontSize = TextUnit.Unspecified,
style = style,
viewId = null,
onClick = onClick,
Expand All @@ -195,21 +188,19 @@ object MarkdownHelper {
private fun createTextView(
context: Context,
color: Color = Color.Unspecified,
defaultColor: Color,
fontSize: TextUnit = TextUnit.Unspecified,
textAlign: TextAlign? = null,
@FontRes fontResource: Int? = null,
style: TextStyle,
@IdRes viewId: Int? = null,
onClick: (() -> Unit)? = null,
onLongClick: ((View) -> Boolean)? = null,
): TextView {
val textColor = color.takeOrElse { style.color.takeOrElse { defaultColor } }
val textColor = color.takeOrElse { style.color }
val mergedStyle =
style.merge(
TextStyle(
color = textColor,
fontSize = if (fontSize != TextUnit.Unspecified) fontSize else style.fontSize,
fontSize = style.fontSize,
textAlign = textAlign ?: TextAlign.Unspecified,
),
)
Expand Down Expand Up @@ -244,18 +235,15 @@ object MarkdownHelper {
fun CreateMarkdownPreview(
markdown: String,
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.onSurface,
color: Color = Color.Unspecified,
onClick: (() -> Unit)? = null,
style: TextStyle,
defaultColor: Color,
) {
AndroidView(
factory = { ctx ->
createTextViewPreview(
context = ctx,
color = color,
defaultColor = defaultColor,
fontSize = TextUnit.Unspecified,
style = style,
onClick = onClick,
)
Expand All @@ -270,18 +258,16 @@ object MarkdownHelper {
private fun createTextViewPreview(
context: Context,
color: Color = Color.Unspecified,
defaultColor: Color,
fontSize: TextUnit = TextUnit.Unspecified,
maxLines: Int = 5,
style: TextStyle,
onClick: (() -> Unit)? = null,
): TextView {
val textColor = color.takeOrElse { style.color.takeOrElse { defaultColor } }
val textColor = color.takeOrElse { style.color }
val mergedStyle =
style.merge(
TextStyle(
color = textColor,
fontSize = if (fontSize != TextUnit.Unspecified) fontSize else style.fontSize,
fontSize = style.fontSize,
),
)
return TextView(context).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Comment
import androidx.compose.material.icons.filled.Bookmark
Expand All @@ -35,6 +33,7 @@ import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
Expand All @@ -47,7 +46,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
Expand Down Expand Up @@ -496,12 +494,9 @@ fun PostBody(
}
}
} else {
val defaultColor: Color =
LocalContentColor.current.copy(alpha = LocalContentAlpha.current)

CreateMarkdownPreview(
markdown = text,
defaultColor = defaultColor,
color = LocalContentColor.current,
onClick = clickBody,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(MEDIUM_PADDING),
Expand Down

0 comments on commit a935664

Please sign in to comment.