Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #819 from matrix-org/jonny/android-font-size-config
Browse files Browse the repository at this point in the history
[Android] Allow font size customisation in compose
  • Loading branch information
Alfonso Grillo authored Sep 20, 2023
2 parents 68ad9e2 + 62a8814 commit 49ef056
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.element.android.wysiwyg.compose

import android.os.Build
import android.util.TypedValue
import android.view.View
import androidx.appcompat.widget.AppCompatEditText
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -172,6 +173,7 @@ private fun PreviewEditor(

private fun AppCompatEditText.applyStyle(style: RichTextEditorStyle) {
setTextColor(style.text.color.toArgb())
setTextSize(TypedValue.COMPLEX_UNIT_SP, style.text.fontSize.value)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val cursorDrawable = ContextCompat.getDrawable(context, R.drawable.cursor)
cursorDrawable?.setTint(style.cursor.color.toArgb())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp

private val defaultCodeCornerRadius = 4.dp
Expand Down Expand Up @@ -121,8 +122,10 @@ object RichTextEditorDefaults {
@Composable
fun textStyle(
color: Color = MaterialTheme.colorScheme.onSurface,
fontSize: TextUnit = MaterialTheme.typography.bodyLarge.fontSize,
) = TextStyle(
color = color,
fontSize = fontSize,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import kotlin.math.roundToInt

data class RichTextEditorStyle internal constructor(
Expand Down Expand Up @@ -43,6 +44,7 @@ data class PillStyle(

data class TextStyle(
val color: Color,
val fontSize: TextUnit,
)

data class CursorStyle(
Expand Down

0 comments on commit 49ef056

Please sign in to comment.