Skip to content

Commit acdd575

Browse files
committed
style(bills): apply font scaling to text on bills
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent ad3ee99 commit acdd575

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

apps/flipcash/shared/bills/src/main/kotlin/com/flipcash/app/bills/BillAmount.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@ import androidx.compose.runtime.Composable
77
import androidx.compose.ui.Modifier
88
import androidx.compose.ui.draw.rotate
99
import androidx.compose.ui.layout.layout
10+
import androidx.compose.ui.text.TextStyle
11+
import androidx.compose.ui.text.font.FontWeight
1012
import androidx.compose.ui.tooling.preview.Preview
13+
import androidx.compose.ui.unit.min
14+
import androidx.compose.ui.unit.sp
1115
import com.flipcash.shared.bills.R
1216
import com.getcode.theme.CodeTheme
1317
import com.getcode.ui.utils.nonScaledSp
1418

1519
@Composable
16-
@Preview
17-
internal fun BillAmount(modifier: Modifier = Modifier, text: String = "", flag: Int? = R.drawable.ic_flag_us) {
20+
internal fun BillAmount(
21+
modifier: Modifier = Modifier,
22+
text: String = "",
23+
flag: Int? = R.drawable.ic_flag_us,
24+
textStyle: TextStyle = CodeTheme.typography.displayLarge.copy(
25+
fontWeight = FontWeight.W600,
26+
fontSize = 50.nonScaledSp
27+
)
28+
) {
1829
Box(modifier = modifier) {
1930
Row(
2031
modifier = Modifier
@@ -35,9 +46,7 @@ internal fun BillAmount(modifier: Modifier = Modifier, text: String = "", flag:
3546
// }
3647
Text(
3748
text = text,
38-
style = CodeTheme.typography.displayLarge.copy(
39-
fontSize = 40.nonScaledSp
40-
),
49+
style = textStyle,
4150
color = CodeTheme.colors.onBackground
4251
)
4352
}

apps/flipcash/shared/bills/src/main/kotlin/com/flipcash/app/bills/CashBill.kt

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
4646
import androidx.compose.ui.layout.ContentScale
4747
import androidx.compose.ui.platform.LocalResources
4848
import androidx.compose.ui.res.painterResource
49+
import androidx.compose.ui.text.TextStyle
50+
import androidx.compose.ui.text.font.FontWeight
4951
import androidx.compose.ui.unit.Dp
5052
import androidx.compose.ui.unit.DpOffset
5153
import androidx.compose.ui.unit.DpSize
5254
import androidx.compose.ui.unit.IntOffset
5355
import androidx.compose.ui.unit.IntSize
56+
import androidx.compose.ui.unit.TextUnit
5457
import androidx.compose.ui.unit.dp
5558
import androidx.compose.ui.unit.isSpecified
59+
import androidx.compose.ui.unit.sp
5660
import com.flipcash.app.core.money.formatted
5761
import com.flipcash.shared.bills.R
5862
import com.getcode.opencode.compose.LocalExchange
@@ -105,6 +109,7 @@ private object CashBillDefaults {
105109
endY = endY
106110
)
107111
}
112+
108113
is BillBackground.Solid -> {
109114
val color = hexToColor(background.colorHex)
110115
return Brush.verticalGradient(
@@ -141,6 +146,7 @@ private object CashBillDefaults {
141146
colors = listOf(color, color)
142147
)
143148
}
149+
144150
Punch.Code -> {
145151
val bgColors = if (bg.colors.size == 3) {
146152
bg.colors.slice(listOf(0, 2))
@@ -172,6 +178,7 @@ private object CashBillDefaults {
172178
colors = listOf(color, color)
173179
)
174180
}
181+
175182
Punch.Code -> {
176183
val color = deriveTargetColor(
177184
sourceColor = hexToColor(bg.colorHex),
@@ -249,6 +256,37 @@ private class CashBillGeometry(width: Dp, height: Dp) : Geometry(width, height)
249256
x = (size.width.value * 0.5f),
250257
y = (size.height.value * 0.9f)
251258
)
259+
260+
private val isCompressed: Boolean
261+
get() = size.width < 300.dp
262+
263+
private val isMini: Boolean
264+
get() = size.width < 200.dp
265+
266+
val mintFontSize: TextUnit
267+
@Composable get() = if (isCompressed) {
268+
if (isMini) {
269+
4.sp
270+
} else {
271+
7.sp
272+
}
273+
} else {
274+
8.nonScaledSp
275+
}
276+
277+
val amountTextStyle: TextStyle
278+
@Composable get() = if (isCompressed) {
279+
CodeTheme.typography.displayLarge.copy(
280+
fontWeight = FontWeight.W600,
281+
fontSize = if (isMini) 30.sp else 35.sp
282+
)
283+
} else {
284+
CodeTheme.typography.displayLarge.copy(
285+
fontWeight = FontWeight.W600,
286+
fontSize = 50.nonScaledSp
287+
)
288+
}
289+
252290
}
253291

254292
@SuppressLint("UnusedBoxWithConstraintsScope")
@@ -341,25 +379,26 @@ internal fun CashBill(
341379
// Security strip
342380
SecurityStrip(geometry = geometry, token = token)
343381

344-
345382
// Bill Value Top Left
346383
BillAmount(
347-
modifier = Modifier.Companion
384+
modifier = Modifier
348385
.align(Alignment.TopStart)
349386
.padding(top = geometry.topStripHeight + geometry.securityStripSize.height * 0.5f)
350387
.padding(start = geometry.valuePadding),
351388
text = amount.formatted(),
352-
flag = exchange.getFlagByCurrency(amount.rate.currency.name)
389+
flag = exchange.getFlagByCurrency(amount.rate.currency.name),
390+
textStyle = geometry.amountTextStyle,
353391
)
354392

355393
// Bill Value Bottom Right
356394
BillAmount(
357-
modifier = Modifier.Companion
395+
modifier = Modifier
358396
.align(Alignment.BottomEnd)
359397
.padding(bottom = geometry.topStripHeight + geometry.securityStripSize.height * 0.5f)
360398
.padding(end = geometry.valuePadding),
361399
text = amount.formatted(),
362-
flag = exchange.getFlagByCurrency(amount.rate.currency.name)
400+
flag = exchange.getFlagByCurrency(amount.rate.currency.name),
401+
textStyle = geometry.amountTextStyle,
363402
)
364403

365404
// Lines
@@ -381,15 +420,15 @@ internal fun CashBill(
381420
Lines(count = 31, spacing = geometry.lineSpacing)
382421
}
383422

384-
Spacer(modifier = Modifier.Companion.weight(1f))
423+
Spacer(modifier = Modifier.weight(1f))
385424

386425
Row(
387426
modifier = Modifier.padding(bottom = geometry.mintPadding)
388427
) {
389428
// Mint
390429
Text(
391430
text = token.address.base58(),
392-
fontSize = 8.nonScaledSp,
431+
fontSize = geometry.mintFontSize,
393432
color = CashBillDefaults.DecorColor,
394433
)
395434
}

0 commit comments

Comments
 (0)