Pablo
07/11/2024, 1:58 PMKhubaib Khan
07/11/2024, 2:46 PM@Composable
fun ConditionalText(
text: String,
fontSize: Int
) {
Text(
text = text,
fontSize = fontSize.takeIf { it != 0 }?.sp ?: 16.sp
)
}
Or
You can use this one as well:
fontSize = if (fontSize != 0) fontSize.sp else 16.sp
Pablo
07/11/2024, 2:49 PMPablo
07/11/2024, 2:49 PMPablo
07/11/2024, 2:49 PMZach Klippenstein (he/him) [MOD]
07/11/2024, 9:09 PMText
, eg
if (fontSize != 0) {
Text(text = text, fontSize = fontSize.sp)
} else {
Text(text = text)
}
Pablo
07/12/2024, 6:45 AMPablo
07/12/2024, 6:46 AMPablo
07/12/2024, 6:46 AMText(
text = text,
color = intColor?.let { Color(intColor) } ?: Color.Unspecified,
fontSize = spTextSize ?: oldTextSize ?: TextUnit.Unspecified,
modifier = modifier
)
Zach Klippenstein (he/him) [MOD]
07/12/2024, 1:37 PMUnspecified
, and even if they did the function would still need to handle those values, so it’s pretty safePablo
07/12/2024, 2:16 PMPablo
07/12/2024, 2:16 PMPablo
07/12/2024, 2:16 PMA special TextUnit instance for representing inheriting from parent value.
Notice that performing arithmetic operations on Unspecified may result in an IllegalArgumentException.
Pablo
07/12/2024, 2:17 PMPablo
07/12/2024, 2:18 PMephemient
07/13/2024, 8:02 PMnull
which would force boxing for primitive/value types)