Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
add a double-row BalanceRow style, bring back the 4-character asteris…
Browse files Browse the repository at this point in the history
…k style
  • Loading branch information
nvllz committed Jan 21, 2024
1 parent f2f7ad1 commit 2fbbf60
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 119 deletions.
3 changes: 2 additions & 1 deletion screen-home/src/main/java/com/ivy/home/HomeHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ private fun HeaderStickyRow(
currency = currency,
balance = balance,
shortenBigNumbers = true,
hiddenMode = hideBalance
hiddenMode = hideBalance,
doubleRowDisplay = true,

)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.ivy.wallet.ui.theme.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -24,145 +27,179 @@ import com.ivy.legacy.utils.shouldShortAmount
@Deprecated("Old design system. Use `:ivy-design` and Material3")
@Composable
fun BalanceRowMedium(
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
balanceAmountPrefix: String? = null,
currencyUpfront: Boolean = true,
shortenBigNumbers: Boolean = false,
hiddenMode: Boolean = false,
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
balanceAmountPrefix: String? = null,
currencyUpfront: Boolean = true,
shortenBigNumbers: Boolean = false,
hiddenMode: Boolean = false,
) {
BalanceRow(
modifier = modifier,

textColor = textColor,
currency = currency,
balance = balance,
hiddenMode = hiddenMode,
spacerCurrency = 12.dp,
currencyFontSize = 24.sp,
balanceFontSize = 26.sp,

balanceAmountPrefix = balanceAmountPrefix,
currencyUpfront = currencyUpfront,
shortenBigNumbers = shortenBigNumbers
modifier = modifier,

textColor = textColor,
currency = currency,
balance = balance,
hiddenMode = hiddenMode,
spacerCurrency = 12.dp,
currencyFontSize = 24.sp,
balanceFontSize = 26.sp,

balanceAmountPrefix = balanceAmountPrefix,
currencyUpfront = currencyUpfront,
shortenBigNumbers = shortenBigNumbers
)
}

@Composable
fun BalanceRowMini(
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
balanceAmountPrefix: String? = null,
currencyUpfront: Boolean = true,
shortenBigNumbers: Boolean = false,
hiddenMode: Boolean = false,
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
balanceAmountPrefix: String? = null,
currencyUpfront: Boolean = true,
shortenBigNumbers: Boolean = false,
hiddenMode: Boolean = false,
doubleRowDisplay: Boolean = false,
) {
BalanceRow(
modifier = modifier,

textColor = textColor,
currency = currency,
balance = balance,
hiddenMode = hiddenMode,
spacerCurrency = 8.dp,
currencyFontSize = 20.sp,
balanceFontSize = 22.sp,

balanceAmountPrefix = balanceAmountPrefix,
currencyUpfront = currencyUpfront,
shortenBigNumbers = shortenBigNumbers
modifier = modifier,

textColor = textColor,
currency = currency,
balance = balance,
hiddenMode = hiddenMode,
spacerCurrency = 8.dp,
currencyFontSize = 20.sp,
balanceFontSize = 22.sp,

balanceAmountPrefix = balanceAmountPrefix,
currencyUpfront = currencyUpfront,
shortenBigNumbers = shortenBigNumbers,
doubleRowDisplay = doubleRowDisplay
)
}

@Composable
fun BalanceRow(
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
hiddenMode: Boolean = false,
spacerCurrency: Dp = 12.dp,
currencyFontSize: TextUnit? = null,
balanceFontSize: TextUnit? = null,
currencyUpfront: Boolean = true,
balanceAmountPrefix: String? = null,
shortenBigNumbers: Boolean = false,
currency: String,
balance: Double,
modifier: Modifier = Modifier,
textColor: Color = UI.colors.pureInverse,
hiddenMode: Boolean = false,
spacerCurrency: Dp = 12.dp,
currencyFontSize: TextUnit? = null,
balanceFontSize: TextUnit? = null,
currencyUpfront: Boolean = true,
balanceAmountPrefix: String? = null,
shortenBigNumbers: Boolean = false,
doubleRowDisplay: Boolean = false,
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically
) {
val shortAmount = shortenBigNumbers && shouldShortAmount(balance)
val shortAmount = shortenBigNumbers && shouldShortAmount(balance)
val integerPartFormatted = if (shortAmount) {
shortenAmount(balance)
} else {
balance.format(currency)
}

if (currencyUpfront) {
Currency(
Column(
modifier = modifier,
verticalArrangement = Arrangement.Center
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
if (currencyUpfront || doubleRowDisplay) {
Currency(
currency = currency,
textColor = textColor,
currencyFontSize = currencyFontSize
)

Spacer(Modifier.width(spacerCurrency))
}
)
Spacer(Modifier.width(spacerCurrency))
}

val integerPartFormatted = if (shortAmount) {
shortenAmount(balance)
} else {
balance.format(currency)
}
Text(
text = when {
hiddenMode -> "*"
balanceAmountPrefix != null -> "$balanceAmountPrefix$integerPartFormatted"
else -> integerPartFormatted
},
style = if (balanceFontSize == null) {
UI.typo.nH1.style(
if (!doubleRowDisplay) {
Text(
text = when {
hiddenMode -> "****"
balanceAmountPrefix != null -> "$balanceAmountPrefix$integerPartFormatted"
else -> integerPartFormatted
},
style = if (balanceFontSize == null) {
UI.typo.nH1.style(
fontWeight = FontWeight.ExtraBold,
color = textColor
)
} else {
UI.typo.nH1.style(
)
} else {
UI.typo.nH1.style(
fontWeight = FontWeight.ExtraBold,
color = textColor
).copy(fontSize = balanceFontSize)
}
)

if (!currencyUpfront) {
Spacer(Modifier.width(spacerCurrency))
).copy(fontSize = balanceFontSize)
}
)
}

Currency(
if (!currencyUpfront && !doubleRowDisplay) {
Spacer(Modifier.width(spacerCurrency))
Currency(
currency = currency,
textColor = textColor,
currencyFontSize = currencyFontSize
)
)
}
}

if (doubleRowDisplay) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = when {
hiddenMode -> "****"
balanceAmountPrefix != null -> "$balanceAmountPrefix$integerPartFormatted"
else -> integerPartFormatted
},
style = if (balanceFontSize == null) {
UI.typo.nH1.style(
fontWeight = FontWeight.ExtraBold,
color = textColor
)
} else {
UI.typo.nH1.style(
fontWeight = FontWeight.ExtraBold,
color = textColor
).copy(fontSize = balanceFontSize)
}
)
}
}
}
}

@Composable
private fun Currency(
currency: String,
currencyFontSize: TextUnit?,
textColor: Color,
currency: String,
currencyFontSize: TextUnit?,
textColor: Color,
) {
Text(
text = currency,
style = if (currencyFontSize == null) {
UI.typo.h1.style(
fontWeight = FontWeight.Light,
color = textColor
)
} else {
UI.typo.h1.style(
fontWeight = FontWeight.Light,
color = textColor
).copy(fontSize = currencyFontSize)
}
text = currency,
style = if (currencyFontSize == null) {
UI.typo.h1.style(
fontWeight = FontWeight.Light,
color = textColor
)
} else {
UI.typo.h1.style(
fontWeight = FontWeight.Light,
color = textColor
).copy(fontSize = currencyFontSize)
}
)
}

Expand All @@ -171,11 +208,11 @@ private fun Currency(
private fun Preview_Default() {
IvyWalletComponentPreview {
BalanceRow(
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520000.60,
balanceAmountPrefix = null,
shortenBigNumbers = true
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520000.60,
balanceAmountPrefix = null,
shortenBigNumbers = true
)
}
}
Expand All @@ -185,10 +222,10 @@ private fun Preview_Default() {
private fun Preview_Medium() {
IvyWalletComponentPreview {
BalanceRowMedium(
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520.60,
balanceAmountPrefix = null
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520.60,
balanceAmountPrefix = null
)
}
}
Expand All @@ -198,11 +235,11 @@ private fun Preview_Medium() {
private fun Preview_Mini() {
IvyWalletComponentPreview {
BalanceRowMini(
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520.60,
balanceAmountPrefix = null,
shortenBigNumbers = true
textColor = UI.colors.pureInverse,
currency = "BGN",
balance = 3520.60,
balanceAmountPrefix = null,
shortenBigNumbers = true
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fun AmountCurrencyB1(
) {
val shortAmount = shortenBigNumbers && shouldShortAmount(amount)
val text = if (hideIncome) {
"*"
"****"
} else {
if (shortAmount) shortenAmount(amount) else amount.format(currency)
}
Expand Down

0 comments on commit 2fbbf60

Please sign in to comment.