From c09f09a37ec780898ec714d359708864ac571d85 Mon Sep 17 00:00:00 2001 From: Hector Delgado Date: Thu, 27 Jun 2024 16:04:15 -0700 Subject: [PATCH] Use gravity to align text correctly --- .../compose/markdowntext/TextAppearanceExt.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/TextAppearanceExt.kt b/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/TextAppearanceExt.kt index 3706441..d6c12f9 100644 --- a/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/TextAppearanceExt.kt +++ b/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/TextAppearanceExt.kt @@ -7,7 +7,7 @@ import android.os.Build import android.text.SpannableStringBuilder import android.text.Spanned import android.util.TypedValue -import android.view.View +import android.view.Gravity import android.widget.TextView import androidx.annotation.FontRes import androidx.compose.ui.text.TextStyle @@ -92,11 +92,11 @@ fun TextView.applyLineHeight(textStyle: TextStyle) { } fun TextView.applyTextAlign(align: TextAlign) { - textAlignment = when (align) { - TextAlign.Left, TextAlign.Start -> View.TEXT_ALIGNMENT_TEXT_START - TextAlign.Right, TextAlign.End -> View.TEXT_ALIGNMENT_TEXT_END - TextAlign.Center -> View.TEXT_ALIGNMENT_CENTER - else -> View.TEXT_ALIGNMENT_TEXT_START + gravity = when (align) { + TextAlign.Left, TextAlign.Start -> Gravity.START + TextAlign.Right, TextAlign.End -> Gravity.END + TextAlign.Center -> Gravity.CENTER_HORIZONTAL + else -> Gravity.START } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && align == TextAlign.Justify) {