Skip to content

Commit 22bccbf

Browse files
committed
chore(amountarea): allow specifiying textStyle to control max text size in reuse
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent d2fbbb6 commit 22bccbf

7 files changed

Lines changed: 97 additions & 49 deletions

File tree

app/src/main/java/com/getcode/view/main/balance/BalanceSheet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fun BalanceTop(
285285
isLoading = state.historicalTransactionsLoading,
286286
currencyResId = state.currencyFlag,
287287
isClickable = isClickable,
288-
onClick = onClick
288+
onClick = onClick,
289289
)
290290
}
291291

app/src/main/java/com/getcode/view/main/giveKin/AmountArea.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import androidx.compose.ui.Alignment.Companion.CenterVertically
1515
import androidx.compose.ui.Modifier
1616
import androidx.compose.ui.graphics.Color
1717
import androidx.compose.ui.res.painterResource
18+
import androidx.compose.ui.text.TextStyle
1819
import androidx.compose.ui.text.style.TextAlign
1920
import androidx.compose.ui.tooling.preview.Preview
21+
import androidx.compose.ui.unit.TextUnit
2022
import com.getcode.LocalNetworkObserver
2123
import com.getcode.R
2224
import com.getcode.theme.Alert
@@ -42,6 +44,7 @@ fun AmountArea(
4244
isClickable: Boolean = true,
4345
isLoading: Boolean = false,
4446
isAnimated: Boolean = false,
47+
textStyle: TextStyle = CodeTheme.typography.h1,
4548
uiModel: AmountAnimatedInputUiModel? = null,
4649
networkState: NetworkState = LocalNetworkObserver.current.state.value,
4750
onClick: () -> Unit = {}
@@ -59,14 +62,16 @@ fun AmountArea(
5962
if (!isAnimated) {
6063
AmountText(
6164
currencyResId = currencyResId,
62-
"${amountPrefix.orEmpty()}$amountText${amountSuffix.orEmpty()}"
65+
amountText = "${amountPrefix.orEmpty()}$amountText${amountSuffix.orEmpty()}",
66+
textStyle = textStyle,
6367
)
6468
} else {
6569
AmountTextAnimated(
6670
uiModel = uiModel,
6771
currencyResId = currencyResId,
6872
amountPrefix = amountPrefix.orEmpty(),
69-
amountSuffix = amountSuffix.orEmpty()
73+
amountSuffix = amountSuffix.orEmpty(),
74+
textStyle = textStyle,
7075
)
7176
}
7277
}

app/src/main/java/com/getcode/view/main/giveKin/AmountText.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.ui.draw.clip
1111
import androidx.compose.ui.draw.drawWithContent
1212
import androidx.compose.ui.res.painterResource
1313
import androidx.compose.ui.text.TextLayoutResult
14+
import androidx.compose.ui.text.TextStyle
1415
import androidx.compose.ui.text.style.TextAlign
1516
import com.getcode.theme.CodeTheme
1617
import com.getcode.theme.White
@@ -19,9 +20,10 @@ import com.getcode.theme.displayLarge
1920
@Composable
2021
fun AmountText(
2122
currencyResId: Int?,
22-
amountText: String
23+
amountText: String,
24+
textStyle: TextStyle = CodeTheme.typography.h1,
2325
) {
24-
val displayLarge = CodeTheme.typography.displayLarge.copy(textAlign = TextAlign.Center)
26+
val displayLarge = textStyle.copy(textAlign = TextAlign.Center)
2527
var scaledTextStyle by remember { mutableStateOf(displayLarge) }
2628
var isReadyToDraw by remember { mutableStateOf(false) }
2729

app/src/main/java/com/getcode/view/main/giveKin/AmountTextAnimated.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.ui.draw.clip
1313
import androidx.compose.ui.graphics.Color
1414
import androidx.compose.ui.platform.LocalDensity
1515
import androidx.compose.ui.res.painterResource
16+
import androidx.compose.ui.text.TextStyle
1617
import androidx.compose.ui.text.font.FontWeight
1718
import androidx.compose.ui.text.style.TextOverflow
1819
import androidx.compose.ui.unit.*
@@ -132,11 +133,12 @@ fun AnimatedPlaceholderDigit(
132133

133134
@ExperimentalAnimationApi
134135
@Composable
135-
fun AmountTextAnimated(
136+
internal fun AmountTextAnimated(
136137
currencyResId: Int?,
137138
amountPrefix: String,
138139
amountSuffix: String,
139140
uiModel: AmountAnimatedInputUiModel?,
141+
textStyle: TextStyle,
140142
) {
141143
uiModel ?: return
142144

@@ -157,10 +159,9 @@ fun AmountTextAnimated(
157159
var firstDigit by remember { mutableStateOf("") }
158160

159161
//Font states
160-
val displayLarge = CodeTheme.typography.displayLarge
161-
var textSize by remember { mutableStateOf(displayLarge.fontSize) }
162+
var textSize by remember { mutableStateOf(textStyle.fontSize) }
162163
val fontDecreasePoints = remember { HashMap<Int, Float>() }
163-
val maxFontSize = displayLarge.fontSize
164+
val maxFontSize = textStyle.fontSize
164165

165166
val commaVisibility = uiModel.amountData.commaVisibility
166167
val amountSplit = uiModel.amountData.amount.split(DECIMAL_SEPARATOR)

app/src/main/java/com/getcode/view/main/giveKin/GiveKinSheet.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.getcode.navigation.screens.HomeResult
2424
import com.getcode.theme.Alert
2525
import com.getcode.theme.BrandLight
2626
import com.getcode.theme.CodeTheme
27+
import com.getcode.theme.displayLarge
2728
import com.getcode.util.showNetworkError
2829
import com.getcode.utils.ErrorUtils
2930
import com.getcode.view.components.ButtonState
@@ -65,6 +66,7 @@ fun GiveKinSheet(
6566
uiModel = dataState.amountAnimatedModel,
6667
isAnimated = true,
6768
networkState = networkState,
69+
textStyle = CodeTheme.typography.displayLarge,
6870
modifier = Modifier
6971
.align(Alignment.Center)
7072
) {

app/src/main/java/com/getcode/view/main/home/HomeScan.kt

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import com.getcode.view.main.home.components.BillManagementOptions
8282
import com.getcode.view.main.home.components.HomeBill
8383
import com.getcode.view.main.home.components.PaymentConfirmation
8484
import com.getcode.view.main.home.components.PermissionsBlockingView
85+
import com.getcode.view.main.home.components.ReceivedKinConfirmation
8586
import kotlinx.coroutines.delay
8687
import kotlinx.coroutines.flow.filterIsInstance
8788
import kotlinx.coroutines.flow.launchIn
@@ -480,46 +481,10 @@ private fun BillContainer(
480481
Box(
481482
contentAlignment = BottomCenter
482483
) {
483-
Column(
484-
modifier = Modifier
485-
.clip(
486-
CodeTheme.shapes.medium.copy(
487-
bottomStart = ZeroCornerSize,
488-
bottomEnd = ZeroCornerSize
489-
)
490-
)
491-
.background(Brand)
492-
.padding(
493-
horizontal = CodeTheme.dimens.inset,
494-
vertical = CodeTheme.dimens.grid.x3
495-
)
496-
.windowInsetsPadding(WindowInsets.navigationBars),
497-
horizontalAlignment = CenterHorizontally
498-
) {
499-
Text(
500-
modifier = Modifier.padding(top = CodeTheme.dimens.grid.x3),
501-
style = CodeTheme.typography.subtitle1.copy(
502-
fontWeight = FontWeight.Bold
503-
),
504-
text = stringResource(id = R.string.subtitle_youReceived)
505-
)
506-
507-
Row {
508-
val bill = updatedState.billState.bill as Bill.Cash
509-
AmountArea(
510-
amountText = bill.amount.formatted(),
511-
currencyResId = bill.amount.rate.currency.flagResId,
512-
isClickable = false
513-
)
514-
515-
}
516-
CodeButton(
517-
modifier = Modifier.fillMaxWidth(),
518-
onClick = { homeViewModel.cancelSend() },
519-
buttonState = ButtonState.Filled,
520-
text = stringResource(id = R.string.action_putInWallet)
521-
)
522-
}
484+
ReceivedKinConfirmation(
485+
bill = updatedState.billState.bill as Bill.Cash,
486+
onClaim = { homeViewModel.cancelSend() }
487+
)
523488
}
524489
}
525490
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.getcode.view.main.home.components
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.WindowInsets
7+
import androidx.compose.foundation.layout.fillMaxWidth
8+
import androidx.compose.foundation.layout.navigationBars
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.windowInsetsPadding
11+
import androidx.compose.foundation.shape.ZeroCornerSize
12+
import androidx.compose.material.Text
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.draw.clip
17+
import androidx.compose.ui.res.stringResource
18+
import androidx.compose.ui.text.font.FontWeight
19+
import com.getcode.R
20+
import com.getcode.models.Bill
21+
import com.getcode.theme.Brand
22+
import com.getcode.theme.CodeTheme
23+
import com.getcode.util.flagResId
24+
import com.getcode.util.formatted
25+
import com.getcode.view.components.ButtonState
26+
import com.getcode.view.components.CodeButton
27+
import com.getcode.view.main.giveKin.AmountArea
28+
29+
@Composable
30+
internal fun ReceivedKinConfirmation(
31+
bill: Bill.Cash,
32+
onClaim: () -> Unit,
33+
) {
34+
Column(
35+
modifier = Modifier
36+
.clip(
37+
CodeTheme.shapes.medium.copy(
38+
bottomStart = ZeroCornerSize,
39+
bottomEnd = ZeroCornerSize
40+
)
41+
)
42+
.background(Brand)
43+
.padding(
44+
horizontal = CodeTheme.dimens.inset,
45+
vertical = CodeTheme.dimens.grid.x3
46+
)
47+
.windowInsetsPadding(WindowInsets.navigationBars),
48+
horizontalAlignment = Alignment.CenterHorizontally
49+
) {
50+
Text(
51+
modifier = Modifier.padding(top = CodeTheme.dimens.grid.x3),
52+
style = CodeTheme.typography.subtitle1.copy(
53+
fontWeight = FontWeight.Bold
54+
),
55+
text = stringResource(id = R.string.subtitle_youReceived)
56+
)
57+
58+
Row {
59+
AmountArea(
60+
amountText = bill.amount.formatted(),
61+
currencyResId = bill.amount.rate.currency.flagResId,
62+
isClickable = false
63+
)
64+
65+
}
66+
CodeButton(
67+
modifier = Modifier.fillMaxWidth(),
68+
onClick = onClaim,
69+
buttonState = ButtonState.Filled,
70+
text = stringResource(id = R.string.action_putInWallet)
71+
)
72+
}
73+
}

0 commit comments

Comments
 (0)