Updated on 2026-08-14

This commit is contained in:
Tangem 2025-06-23 12:38:59 +05:00
commit 929317d15c
15 changed files with 586 additions and 92 deletions

View file

@ -60,7 +60,10 @@ fun AmountTextField(
modifier: Modifier = Modifier,
color: Color = TangemTheme.colors.text.primary1,
backgroundColor: Color = TangemTheme.colors.background.action,
visualTransformation: VisualTransformation = AmountVisualTransformation(decimals),
visualTransformation: VisualTransformation = AmountVisualTransformation(
decimals = decimals,
symbolColor = if (value.isBlank()) TangemTheme.colors.text.disabled else color,
),
keyboardOptions: KeyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
),

View file

@ -1,9 +1,12 @@
package com.tangem.core.ui.components.fields.visualtransformations
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
import com.tangem.core.ui.extensions.appendColored
import com.tangem.core.ui.format.bigdecimal.BigDecimalFormatConstants
import com.tangem.core.ui.format.bigdecimal.BigDecimalFormatConstants.CURRENCY_SPACE
import com.tangem.core.ui.format.bigdecimal.getJavaCurrencyByCode
@ -19,6 +22,7 @@ class AmountVisualTransformation(
private val symbol: String? = null,
private val currencyCode: String? = null,
private val decimalFormat: DecimalFormat = DecimalFormat(),
private val symbolColor: Color,
) : VisualTransformation {
override fun filter(text: AnnotatedString): TransformedText {
@ -28,17 +32,22 @@ class AmountVisualTransformation(
)
formattedAmount = formattedAmount.ifEmpty { decimalFormat.defaultFormat() }
val formattedText = if (formattedAmount.isNotEmpty() && symbol != null) {
AnnotatedString(
buildAnnotatedString {
if (currencyCode != null) {
formatFiatEditableAmount(
fiatAmount = formattedAmount,
fiatCurrencyCode = currencyCode,
fiatCurrencySymbol = symbol,
append(
formatFiatEditableAmount(
fiatAmount = formattedAmount,
fiatCurrencyCode = currencyCode,
fiatCurrencySymbol = symbol,
fiatCurrencySymbolColor = symbolColor,
),
)
} else {
formatWithSymbol(formattedAmount, symbol)
},
)
append(formattedAmount)
append(CURRENCY_SPACE)
appendColored(symbol, symbolColor)
}
}
} else {
AnnotatedString(decimalFormat.defaultFormat())
}
@ -54,9 +63,10 @@ class AmountVisualTransformation(
fiatAmount: String?,
fiatCurrencyCode: String,
fiatCurrencySymbol: String,
fiatCurrencySymbolColor: Color,
locale: Locale = Locale.getDefault(),
): String {
if (fiatAmount == null) return BigDecimalFormatConstants.EMPTY_BALANCE_SIGN
): AnnotatedString {
if (fiatAmount == null) return AnnotatedString(BigDecimalFormatConstants.EMPTY_BALANCE_SIGN)
val formatterCurrency = getJavaCurrencyByCode(fiatCurrencyCode)
val numberFormatter = NumberFormat.getCurrencyInstance(locale).apply {
@ -64,14 +74,21 @@ class AmountVisualTransformation(
}
val formatter = requireNotNull(numberFormatter as? DecimalFormat) {
Timber.e("NumberFormat is null")
return BigDecimalFormatConstants.EMPTY_BALANCE_SIGN
return AnnotatedString(BigDecimalFormatConstants.EMPTY_BALANCE_SIGN)
}
return buildAnnotatedString {
appendColored(
formatter.positivePrefix.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol),
fiatCurrencySymbolColor,
)
append(fiatAmount)
appendColored(
formatter.positiveSuffix.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol),
fiatCurrencySymbolColor,
)
}
return "${formatter.positivePrefix}$fiatAmount${formatter.positiveSuffix}"
.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol)
}
private fun formatWithSymbol(amount: String, symbol: String) = "$amount$CURRENCY_SPACE$symbol"
private class OffsetMappingImpl(
private val text: String,
private val formattedText: AnnotatedString,

View file

@ -82,6 +82,7 @@ fun InputRowEnterAmount(
decimals = decimals,
symbol = symbol,
decimalFormat = rememberDecimalFormat(),
symbolColor = textColor,
),
onValueChange = onValueChange,
color = textColor,

View file

@ -82,6 +82,7 @@ fun InputRowEnterInfoAmount(
decimals = decimals,
symbol = symbol,
decimalFormat = rememberDecimalFormat(),
symbolColor = textColor,
),
onValueChange = onValueChange,
color = textColor,
@ -120,6 +121,7 @@ fun InputRowEnterInfoAmountV2(
titleColor: Color = TangemTheme.colors.text.secondary,
textColor: Color = TangemTheme.colors.text.primary1,
infoColor: Color = TangemTheme.colors.text.tertiary,
symbolColor: Color = TangemTheme.colors.text.primary1,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
showDivider: Boolean = false,
@ -154,6 +156,7 @@ fun InputRowEnterInfoAmountV2(
decimals = decimals,
symbol = symbol,
decimalFormat = rememberDecimalFormat(),
symbolColor = symbolColor,
),
onValueChange = onValueChange,
color = textColor,

View file

@ -82,7 +82,7 @@ fun Modifier.selectedBorder(
color = color,
shape = RoundedCornerShape(radius),
)
.padding(2.5.dp)
.padding(width)
.border(
width = 1.dp,
color = TangemTheme.colors.text.accent,
@ -91,7 +91,7 @@ fun Modifier.selectedBorder(
.clip(RoundedCornerShape(radius - 2.dp))
},
otherModifier = {
padding(2.dp)
padding(width)
.clip(RoundedCornerShape(radius - 2.dp))
},
)