Skip to content

Commit

Permalink
Factorize the fact of keep the button's size when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 17, 2024
1 parent 8251dde commit aa36469
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,13 @@ private fun CoreButton(
when {
progress != null -> {
val (progressColor, progressModifier) = getProgressSpecs(buttonColors)
Box(contentAlignment = Alignment.Center) {
ButtonTextContent(imageVector, titleRes, Modifier.alpha(0f))
KeepButtonSize(imageVector, titleRes) {
CircularProgressIndicator(modifier = progressModifier, color = progressColor, progress = progress)
}
}
showIndeterminateProgress() -> {
val (progressColor, progressModifier) = getProgressSpecs(buttonColors)
Box(contentAlignment = Alignment.Center) {
ButtonTextContent(imageVector, titleRes, Modifier.alpha(0f))
KeepButtonSize(imageVector, titleRes) {
CircularProgressIndicator(modifier = progressModifier, color = progressColor)
}
}
Expand All @@ -143,16 +141,24 @@ private fun CoreButton(
}

@Composable
private fun ButtonTextContent(imageVector: ImageVector?, titleRes: Int, modifier: Modifier = Modifier) {
Row(modifier = modifier) {
imageVector?.let {
Icon(modifier = Modifier.size(Margin.Medium), imageVector = it, contentDescription = null)
Spacer(modifier = Modifier.width(Margin.Small))
fun KeepButtonSize(imageVector: ImageVector?, titleRes: Int, content: @Composable () -> Unit) {
Box(contentAlignment = Alignment.Center) {
Row(modifier = Modifier.alpha(0f)) {
ButtonTextContent(imageVector, titleRes)
}
Text(text = stringResource(id = titleRes), style = SwissTransferTheme.typography.bodyMedium)
content()
}
}

@Composable
private fun ButtonTextContent(imageVector: ImageVector?, titleRes: Int) {
imageVector?.let {
Icon(modifier = Modifier.size(Margin.Medium), imageVector = it, contentDescription = null)
Spacer(modifier = Modifier.width(Margin.Small))
}
Text(text = stringResource(id = titleRes), style = SwissTransferTheme.typography.bodyMedium)
}

@Composable
private fun getProgressSpecs(buttonColors: ButtonColors): Pair<Color, Modifier> {
val progressColor = buttonColors.disabledContentColor
Expand Down

0 comments on commit aa36469

Please sign in to comment.