Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-29 23:05:18 +03:00
parent 3b04938e54
commit d2bef0bf1a
13 changed files with 557 additions and 8 deletions

View file

@ -0,0 +1,54 @@
package com.tangem.core.ui.components.text
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import com.tangem.core.ui.res.TangemTheme
@Composable
fun TextAnimatedCounter(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = TangemTheme.typography.caption1,
) {
var oldText by remember {
mutableStateOf(text)
}
SideEffect {
oldText = text
}
Row(modifier = modifier) {
for (i in text.indices) {
val oldChar = oldText.getOrNull(i)
val newChar = text[i]
val char = if (oldChar == newChar) {
oldText[i]
} else {
text[i]
}
AnimatedContent(
targetState = char,
transitionSpec = {
slideInVertically { it }.togetherWith(slideOutVertically { -it })
},
) { char ->
Text(
text = char.toString(),
style = style,
softWrap = false,
)
}
}
}
}

View file

@ -117,6 +117,24 @@ fun BigDecimalFiatFormat.price(): BigDecimalFormat = BigDecimalFormat { value ->
.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol)
}
/**
* Formats fiat amount with an exact number of fractional digits.
*/
fun BigDecimalFiatFormat.anyDecimals(decimals: Int): BigDecimalFormat = BigDecimalFormat { value ->
val formatterCurrency = getJavaCurrencyByCode(fiatCurrencyCode)
val formatter = NumberFormat.getCurrencyInstance(locale).apply {
currency = formatterCurrency
maximumFractionDigits = decimals
minimumFractionDigits = decimals
isGroupingUsed = true
roundingMode = RoundingMode.HALF_UP
}
formatter.format(value)
.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol)
}
// == Helpers ==
private fun BigDecimal.isLessThanThreshold() = this > BigDecimal.ZERO && this < FIAT_FORMAT_THRESHOLD