Skip to content

Commit

Permalink
ANDROID-13783 Update. Retro-compatibility for Button padding
Browse files Browse the repository at this point in the history
  • Loading branch information
haynlo committed Sep 26, 2023
1 parent 7de8c99 commit 06a7777
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import com.telefonica.mistica.compose.theme.brand.MovistarBrand

private val iconSpacing = 10.dp
private val easing = CubicBezierEasing(0.77f, 0f, 0.175f, 1f)
private const val CHEVRON_ASPECT_RATIO = 8f/20f
private const val CHEVRON_ASPECT_RATIO = 8f / 20f

@Composable
fun Button(
Expand All @@ -62,6 +62,7 @@ fun Button(
enabled: Boolean = true,
@DrawableRes icon: Int? = null,
withChevron: Boolean = false,
invalidatePaddings: Boolean = false,
onClickListener: () -> Unit,
) {

Expand All @@ -84,7 +85,7 @@ fun Button(
}
.height(size.height)
.applyWidth(originalWidth),
contentPadding = PaddingValues(horizontal = size.horizontalPadding, vertical = 0.dp),
contentPadding = PaddingValues(horizontal = if (invalidatePaddings) 0.dp else size.horizontalPadding, vertical = 0.dp),
onClick = onClickListener,
enabled = enabled,
colors = style.buttonColors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ internal fun ButtonStyle.getButtonSizeCompose(): ButtonSizeConfig =
ButtonStyle.PRIMARY_SMALL,
ButtonStyle.SECONDARY_SMALL_INVERSE,
ButtonStyle.SECONDARY_SMALL,
-> getSmallButtonSizeConfig()
ButtonStyle.LINK,
ButtonStyle.LINK_INVERSE,
-> getSmallButtonSizeConfig().copy(horizontalPadding = 0.dp)
-> getSmallButtonSizeConfig()
else -> getDefaultButtonSizeConfig()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ fun Callout(
}
CalloutButtonConfig.PRIMARY_AND_LINK -> {
PrimaryButton(
modifier = Modifier.padding(end = 16.dp),
text = primaryButtonText,
onClick = onPrimaryButtonClick
modifier = Modifier.padding(end = 16.dp),
onClick = onPrimaryButtonClick,
)
LinkButton(text = linkText, onClick = onLinkClicked)
}
Expand All @@ -107,17 +107,17 @@ fun Callout(
}
CalloutButtonConfig.PRIMARY_AND_SECONDARY -> {
PrimaryButton(
modifier = Modifier.padding(end = 16.dp),
text = primaryButtonText,
onClick = onPrimaryButtonClick
modifier = Modifier.padding(end = 16.dp),
onClick = onPrimaryButtonClick,
)
SecondaryButton(text = secondaryButtonText, onClick = onSecondaryButtonClick)
}
CalloutButtonConfig.SECONDARY_AND_LINK -> {
SecondaryButton(
modifier = Modifier.padding(end = 16.dp),
text = secondaryButtonText,
onClick = onSecondaryButtonClick
modifier = Modifier.padding(end = 16.dp),
onClick = onSecondaryButtonClick,
)
LinkButton(text = linkText, onClick = onLinkClicked)
}
Expand All @@ -142,44 +142,46 @@ fun Callout(

@Composable
private fun PrimaryButton(
modifier: Modifier = Modifier,
text: String?,
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
) {
CalloutButton(modifier, text, onClick, ButtonStyle.PRIMARY_SMALL)
CalloutButton(text = text, onClick = onClick, style = ButtonStyle.PRIMARY_SMALL, modifier = modifier)
}

@Composable
private fun SecondaryButton(
modifier: Modifier = Modifier,
text: String?,
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
) {
CalloutButton(modifier, text, onClick, ButtonStyle.SECONDARY_SMALL)
CalloutButton(text, onClick, ButtonStyle.SECONDARY_SMALL, modifier)
}

@Composable
private fun LinkButton(
modifier: Modifier = Modifier,
text: String?,
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
) {
CalloutButton(modifier, text, onClick, ButtonStyle.LINK)
CalloutButton(text, onClick, ButtonStyle.LINK, modifier, true)
}

@Composable
private fun CalloutButton(
modifier: Modifier = Modifier,
text: String?,
onClick: (() -> Unit)?,
style: ButtonStyle,
modifier: Modifier = Modifier,
invalidatePaddings: Boolean = false,
) {
text?.let {
Button(
modifier = modifier,
text = text,
buttonStyle = style,
onClickListener = { onClick?.invoke() }
onClickListener = { onClick?.invoke() },
invalidatePaddings = invalidatePaddings,
)
}
}
Expand Down

0 comments on commit 06a7777

Please sign in to comment.