nuhkoca
07/07/2022, 9:27 AMcontentPadding
depending on text length? Longer text lesser contentPadding or?Stylianos Gakis
07/07/2022, 9:32 AMfun Modifier.debugBorder(color: Color = Color.Red, width: Dp = 1.dp): Modifier {
return this.border(width, color)
}
nuhkoca
07/07/2022, 9:47 AMStylianos Gakis
07/07/2022, 9:49 AMnuhkoca
07/07/2022, 9:54 AM@Composable
fun SortBy(
label: String,
criteria: String,
direction: Direction,
onSortCriteriaClicked: () -> Unit,
onSortDirectionClicked: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = TRTheme.spacing.default, end = TRTheme.spacing.single),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
TRText(
text = label,
style = TRTheme.typography.subtitle,
color = TRTheme.colors.appForeground2
)
Box(Modifier.weight(1f)) {
TRTextButtonDefault(text = criteria, onClick = onSortCriteriaClicked)
}
TRIconButtonSmall(onClick = onSortDirectionClicked) {
val rotation = animateFloatAsState(targetValue = if (direction == Direction.Ascending) 180f else 0f)
TRIcon(
modifier = TRModifier().graphicsLayer(rotation.value),
iconResId = TRTheme.icons.arrowUpXS,
useLocalColorAndAlpha = true
)
}
}
}
This is our TextButton definition
@Composable
fun TRTextButtonDefault(
modifier: TRModifier = TRModifier(),
text: String,
onClick: () -> Unit,
isEnabled: Boolean = true
) {
TRTextButton(
modifier = modifier,
color = TRTheme.colors.primaryBlue2,
onClick = onClick,
isEnabled = isEnabled
) {
Label(text, TRTheme.typography.subtitle)
}
}
@Composable
private fun Label(text: String, textStyle: TextStyle) {
TRText(
text = text,
maxLines = 1,
style = textStyle,
overflow = TextOverflow.Ellipsis
)
}
Stylianos Gakis
07/07/2022, 10:06 AMnuhkoca
07/09/2022, 11:42 AMTextButton
is a button under the hood, it centers its content. Since my custom font is small-sized, text seems to be a bit more indented when the text is small enough, so root cause was my font size 🙂 However, if I don’t specify any textStyle
, it looks good and consistentStylianos Gakis
07/09/2022, 6:10 PM