TP-42245 added support for MONEY_WITH_RUPEE_SYMBOL in spannable text… (#184)

Co-authored-by: Hitesh Kumar <hitesh.kumar@navi.com>
This commit is contained in:
Soumya Ranjan Patra
2023-09-20 19:46:22 +05:30
committed by GitHub
parent 8c222eeb0a
commit 6ddfafa726
2 changed files with 21 additions and 10 deletions

View File

@@ -16,9 +16,11 @@ import com.navi.uitron.UiTronSdkManager
import com.navi.uitron.model.data.SpannableTextData
import com.navi.uitron.model.data.UiTronData
import com.navi.uitron.model.ui.SpannableProperty
import com.navi.uitron.utils.EMPTY
import com.navi.uitron.viewmodel.UiTronViewModel
import getText
import getTextDecoration
import getTransformedText
import hexToComposeColor
import orFalse
import setBackground
@@ -56,9 +58,12 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
val annotatedString = buildAnnotatedString {
spannableData?.textMap?.let {
spanProperties.forEach { spanProperty ->
val string = spannableData.textMap?.get(spanProperty.stringId) ?: ""
val textData = spannableData.textMap?.get(spanProperty.stringId) ?: EMPTY
val transformedText =
getTransformedText(spanProperty.property.valueTransformation, textData)
?: textData
val startIndex = text.length
val endIndex = text.length + (string.length)
val endIndex = text.length + (transformedText.length)
addStyle(
style = SpanStyle(
fontFamily = UiTronSdkManager.getDependencyProvider()
@@ -74,18 +79,21 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
)
text.append("$string ")
text.append("$transformedText ")
}
append(text.toString())
} ?: run {
spanProperties.forEach { spanProperty ->
val spanData =
spannableData?.spanData?.firstOrNull { it.stringId == spanProperty.stringId }
val spanData = spannableData?.spanData?.firstOrNull {
it.stringId == spanProperty.stringId
}
spanData?.textData?.text?.let {
val transformedText =
getTransformedText(spanProperty.property.valueTransformation, it) ?: it
if (spanData.tag != null) {
pushStringAnnotation(
tag = spanData.tag,
annotation = spanData.annotation ?: "",
annotation = spanData.annotation ?: EMPTY,
)
withStyle(
style = SpanStyle(
@@ -101,7 +109,7 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
?: 0.sp,
)
) {
append(it.getText(spanData.textData.textFormatter))
append(transformedText.getText(spanData.textData.textFormatter))
}
pop()
} else {
@@ -127,7 +135,8 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
}
}
spannableData?.textMap?.let {
BasicText(text = annotatedString,
BasicText(
text = annotatedString,
modifier = (modifier ?: Modifier)
.layoutId(property.layoutId.orEmpty())
.setPadding(property.margin)
@@ -135,7 +144,8 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
property.backgroundColor, property.shape, property.backGroundBrushData
)
.setPadding(property.padding)
.alpha(property.alpha ?: 1.0f))
.alpha(property.alpha ?: 1.0f)
)
} ?: run {
ClickableText(text = annotatedString,
modifier = (modifier ?: Modifier)
@@ -161,4 +171,4 @@ class SpannableTextRenderer : Renderer<SpannableProperty> {
})
}
}
}
}

View File

@@ -339,6 +339,7 @@ fun getTransformedText(
valueTransformation.formatPattern
)
InputTransformationType.MONEY_WITH_RUPEE_SYMBOL.name -> moneyFormat(inputText).let { text ->
if (text.isEmpty()) return text
valueTransformation.prefixText?.let { prefix ->
"$prefix$text"
} ?: "$text"