Skip to content

Commit 403b137

Browse files
nomanrangelix
authored andcommitted
fix: ensure consistent asset card heights
1 parent aef01d1 commit 403b137

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

compose/src/commonMain/kotlin/com/blockstream/compose/components/GreenAsset.kt

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.blockstream.compose.theme.labelLarge
3131
import com.blockstream.compose.theme.titleSmall
3232
import com.blockstream.compose.theme.whiteHigh
3333
import com.blockstream.compose.theme.whiteMedium
34+
import com.blockstream.ui.components.ConsistentHeightBox
3435
import org.jetbrains.compose.resources.painterResource
3536
import org.jetbrains.compose.resources.stringResource
3637

@@ -95,27 +96,11 @@ fun GreenAsset(
9596
}
9697

9798
if (assetBalance.balance != null) {
98-
Column(horizontalAlignment = Alignment.End) {
99-
// Amount
100-
Text(
101-
text = assetBalance.balance ?: "",
102-
style = labelLarge,
103-
maxLines = 1,
104-
overflow = TextOverflow.Ellipsis,
105-
color = green
106-
)
107-
108-
assetBalance.balanceExchange?.also {
109-
// Fiat
110-
Text(
111-
text = it,
112-
style = bodyMedium,
113-
maxLines = 1,
114-
overflow = TextOverflow.Ellipsis,
115-
color = whiteMedium,
116-
)
117-
}
118-
}
99+
ConsistentHeightBox(placeholder = {
100+
BalanceDetails("0", "0")
101+
}, content = {
102+
BalanceDetails(assetBalance.balance, assetBalance.balanceExchange)
103+
})
119104
}
120105
}
121106
}
@@ -133,3 +118,24 @@ fun GreenAsset(
133118
}
134119
}
135120
}
121+
122+
@Composable
123+
private fun BalanceDetails(assetBalance: String?, fiatAssetBalance: String?) {
124+
Column(
125+
horizontalAlignment = Alignment.End, verticalArrangement = Arrangement.Center
126+
) {
127+
Text(
128+
text = assetBalance ?: "", style = labelLarge, maxLines = 1, overflow = TextOverflow.Ellipsis, color = green
129+
)
130+
131+
fiatAssetBalance?.also {
132+
Text(
133+
text = it,
134+
style = bodyMedium,
135+
maxLines = 1,
136+
overflow = TextOverflow.Ellipsis,
137+
color = whiteMedium,
138+
)
139+
}
140+
}
141+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.blockstream.ui.components
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Alignment
6+
import androidx.compose.ui.Modifier
7+
import androidx.compose.ui.draw.alpha
8+
9+
/**
10+
* A composable that maintains consistent height across components by using a placeholder layout.
11+
* The placeholder establishes the maximum height needed, while the actual content is overlaid on top.
12+
*
13+
* @param modifier Modifier to be applied to the Box
14+
* @param placeholder Composable that defines the maximum height layout (rendered invisibly)
15+
* @param content Actual content to be displayed
16+
*/
17+
@Composable
18+
fun ConsistentHeightBox(
19+
modifier: Modifier = Modifier,
20+
contentAlignment: Alignment = Alignment.Center,
21+
placeholder: @Composable () -> Unit,
22+
content: @Composable () -> Unit
23+
) {
24+
Box(modifier = modifier, contentAlignment = contentAlignment) {
25+
Box(modifier = Modifier.alpha(0f)) {
26+
placeholder()
27+
}
28+
29+
content()
30+
}
31+
}

0 commit comments

Comments
 (0)