Порядок модификаторов важен в Jetpack compose, чтобы сделать его видимым, я заключил его в родительский элемент с серым фоном:
Column {
// It just draws a background with out any padding
Stack(modifier = Modifier.drawBackground(Color.Gray)) {
Text(
"Order of modifiers are important",
Modifier.drawBackground(Color.Magenta, RectangleShape)
)
}
Spacer(modifier = Modifier.height(20.dp))
// In this one we put the padding modifier before the drawBackground
// It first adds a padding, what should be the color of that padding?
// so far we didn't tell any thing about it to Jetpack compose so it's transparent
// and shows the color of parent layout that's gray color
// then draws the background behind the content of Text(but doesn't change the color of padding)
Stack(modifier = Modifier.drawBackground(Color.Gray)) {
Text(
"Order of modifiers are important",
Modifier.padding(10.dp).drawBackground(Color.Magenta, RectangleShape)
)
}
Spacer(modifier = Modifier.height(20.dp))
// In this one we put the padding modifier after the drawBackground
// It first draws a background behind the text
// then padding applies but this time it's not transparent, it inherits the color of
// backgroundColor
Stack(modifier = Modifier.drawBackground(Color.Gray)) {
Text(
"Order of modifiers are important",
Modifier.drawBackground(Color.Magenta, RectangleShape).padding(10.dp)
)
}
}