TP-49163 | uat fix : adding letterSpacing support (#10754)

This commit is contained in:
Apoorv Nigam
2024-05-08 10:41:29 +05:30
committed by GitHub
parent b7fd515083
commit d68834aaa2
3 changed files with 37 additions and 1 deletions

View File

@@ -28,7 +28,8 @@ data class NaviSpan(
@SerializedName("gravity") val gravity: String? = null,
@SerializedName("spanBgColor") val spanBgColor: String? = null,
@SerializedName("replacementSpan") val replacementSpan: Boolean? = null,
@SerializedName("cta", alternate = ["action"]) val cta: ActionData? = null
@SerializedName("cta", alternate = ["action"]) val cta: ActionData? = null,
@SerializedName("letterSpacing") val letterSpacing: Float? = null
) : SpanInterface, Serializable, Parcelable {
override fun endSpan(): Int? = endSpan

View File

@@ -330,6 +330,14 @@ fun TextView.setSpannableString(
Spannable.SPAN_INCLUSIVE_INCLUSIVE
)
}
styleData.letterSpacing?.let {
spannableString.setSpan(
LetterSpacingSpan((0.1 * it).toFloat()),
startIndex,
endIndex,
Spannable.SPAN_INCLUSIVE_INCLUSIVE
)
}
}
text = spannableString
clickCta?.let { clickListener?.invoke(it) }

View File

@@ -0,0 +1,27 @@
/*
*
* * Copyright © 2024 by Navi Technologies Limited
* * All rights reserved. Strictly confidential
*
*/
package com.navi.design.utils
import android.graphics.Paint
import android.text.TextPaint
import android.text.style.MetricAffectingSpan
class LetterSpacingSpan(private val letterSpacing: Float) : MetricAffectingSpan() {
override fun updateDrawState(tp: TextPaint?) {
tp?.let { apply(it) }
}
override fun updateMeasureState(textPaint: TextPaint) {
apply(textPaint)
}
private fun apply(paint: Paint) {
paint.letterSpacing = letterSpacing
}
}