TP-49163 | uat fix : adding letterSpacing support (#10754)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user