这只是一种最佳做法.使用其他一些缺省值可能会导致奇怪的情况-假设您想要在一列中使用此组件中的两个:
Column {
DisplayIcon()
DisplayIcon()
}
一切都很好,但现在您想要对齐其中之一:
Column {
DisplayIcon()
DisplayIcon(modifier = Modifier.align(Alignment.End))
}
And suddenly, with no apparent reason, one has different size than the other. So you have to find out from DisplayIcon
implementation what's going on, and then probably add .size(24.dp)
to your aligned composable as well. But now you want to change the default size, and you have to do so on many different places...
Something like this might be better solution:
@Composable
fun DisplayIcon(
modifier: Modifier = Modifier,
icon: ImageVector,
tint: Color = Color.Blue,
size: Dp = 24.dp,
) {
Icon(icon, null, modifier = modifier.size(size), tint = tint)
}