Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove material1 LocalContentColor. #1366

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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