Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROID-14001 Fix chevron glitch on button link #318

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -148,8 +149,6 @@ private fun ButtonContent(
withChevron: Boolean,
enabled: Boolean,
) {
var textHeight by remember { mutableStateOf(0.dp) }
val density = LocalDensity.current
AnimatedVisibility(
modifier = Modifier.fillMaxHeight(),
visible = !isLoading,
Expand All @@ -170,32 +169,31 @@ private fun ButtonContent(
}
Text(
modifier = Modifier
.align(Alignment.CenterVertically)
.onGloballyPositioned {
textHeight = with(density) {
it.size.height.toDp()
}
},
.align(Alignment.CenterVertically),
text = text,
color = textColor,
style = size.textStyle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (withChevron) {
Spacer(modifier = Modifier.width(dimensionResource(id = R.dimen.button_chevron_padding)))
CompositionLocalProvider(
LocalContentAlpha provides if (enabled) ContentAlpha.high else ContentAlpha.disabled,
Box(
modifier = Modifier
.height(IntrinsicSize.Min)
.aspectRatio(CHEVRON_ASPECT_RATIO)
.align(Alignment.CenterVertically)
Comment on lines +180 to +184
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to wrap the whole CompositionLocalProvider element inside a box because it doesn't allow any modifier and IntrinsicSize only applies to direct children of Row

) {
Image(
painterResource(id = R.drawable.icn_chevron),
null,
modifier = Modifier
.height(textHeight)
.aspectRatio(CHEVRON_ASPECT_RATIO)
.align(Alignment.CenterVertically),
colorFilter = ColorFilter.tint(style.textColor.copy(LocalContentAlpha.current)),
)
Spacer(modifier = Modifier.width(dimensionResource(id = R.dimen.button_chevron_padding)))
CompositionLocalProvider(
LocalContentAlpha provides if (enabled) ContentAlpha.high else ContentAlpha.disabled,
) {
Image(
painterResource(id = R.drawable.icn_chevron),
null,
modifier = Modifier.align(Alignment.Center),
colorFilter = ColorFilter.tint(style.textColor.copy(LocalContentAlpha.current)),
)
}
}
}
}
Expand Down