"Added support for Text Alignment in Spannable Text in UITRON" (#196)

This commit is contained in:
Anmol Agrawal
2023-09-29 13:57:27 +05:30
committed by GitHub
parent 04727e9522
commit 4911ca49cb
2 changed files with 10 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package com.navi.uitron.model.ui
data class SpannableProperty(
var textAlign: String? = null,
val spanProperty: List<SpanProperty>
) : BaseProperty()

View File

@@ -9,6 +9,7 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp
@@ -19,6 +20,7 @@ import com.navi.uitron.model.ui.SpannableProperty
import com.navi.uitron.utils.EMPTY
import com.navi.uitron.viewmodel.UiTronViewModel
import getText
import getTextAlignment
import getTextDecoration
import getTransformedText
import hexToComposeColor
@@ -144,7 +146,10 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
property.backgroundColor, property.shape, property.backGroundBrushData
)
.setPadding(property.padding)
.alpha(property.alpha ?: 1.0f)
.alpha(property.alpha ?: 1.0f),
style = TextStyle(
textAlign = getTextAlignment(property.textAlign)
)
)
} ?: run {
ClickableText(text = annotatedString,
@@ -156,6 +161,9 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
)
.setPadding(property.padding)
.alpha(property.alpha ?: 1.0f),
style = TextStyle(
textAlign = getTextAlignment(property.textAlign)
),
onClick = { offset ->
spannableData?.spanData?.forEach { spanData ->
if (spanData.tag != null) {