Fix xml-layout-migration.md#19
Conversation
There was a problem hiding this comment.
Code Review
This pull request corrects markdown syntax and indentation in the XML layout migration documentation. A review comment identifies a discrepancy in how padding is handled when migrating from XML to Jetpack Compose, suggesting the use of the contentPadding parameter instead of Modifier.padding to ensure consistent UI behavior. Additionally, the feedback recommends using named arguments for better readability and replacing hard-coded dimensions with resource references.
| TextButton( | ||
| onClick, modifier | ||
| .defaultMinSize(minWidth = dimensionResource(R.dimen.min_width)) | ||
| .padding( | ||
| start = dimensionResource(R.dimen.padding_2), | ||
| end = dimensionResource(R.dimen.padding_2) | ||
| ), enabled, shape = RoundedCornerShape(8.dp), | ||
| colors = ButtonDefaults.textButtonColors( | ||
| contentColor = MaterialTheme.colorScheme.primary | ||
| ) | ||
| ) { | ||
| Text( | ||
| text = text, | ||
| style = MaterialTheme.typography.bodyMedium.copy( | ||
| fontFamily = FontFamily.SansSerif, | ||
| fontWeight = FontWeight.Medium | ||
| ) | ||
| ) | ||
| } |
There was a problem hiding this comment.
In Jetpack Compose, Modifier.padding applied to a Button (or TextButton) adds padding outside the component's boundaries, which differs from the internal padding behavior of android:padding in XML. To correctly replicate the XML style's padding, use the contentPadding parameter of the TextButton composable. Additionally, using named arguments for all parameters improves readability and maintainability. Note that per the guide's instructions on line 14, hard-coded values like 8.dp should ideally be replaced with dimension resources for consistency.
TextButton(
onClick = onClick,
modifier = modifier.defaultMinSize(minWidth = dimensionResource(R.dimen.min_width)),
enabled = enabled,
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.primary
),
contentPadding = PaddingValues(
start = dimensionResource(R.dimen.padding_2),
end = dimensionResource(R.dimen.padding_2)
)
) {
Text(
text = text,
style = MaterialTheme.typography.bodyMedium.copy(
fontFamily = FontFamily.SansSerif,
fontWeight = FontWeight.Medium
)
)
}
No description provided.