'How to add a padding to elements inside a Chip without hidding elements inside in wear Compose?
The title isn't very clear but if you try this code, you'll see that there is no text (for isLoading = false).
@Composable
fun RefreshButton(
isLoading: Boolean,
onClick: () -> Unit) {
Chip(
label = {
if (isLoading) {
CircularProgressIndicator(
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center)
.padding(32.dp)
)
} else {
Text(
text = "Refresh", modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center)
.padding(32.dp)
)
}
},
onClick = { onClick() },
modifier = Modifier.width(intrinsicSize = IntrinsicSize.Max)
)
}
It works without the padding but I would like to add some padding.
I use wear compose and wear compose-foundation 1.0.0-alpha20.
Solution 1:[1]
My answer below was wrong. Compose components tend to have hardcoded values like size and padding. This is true for Chip.kt. Here's an answer explaining a related question.
bylazy is correct. You should apply padding to the parent, not the content
isLoading: Boolean, onClick: () -> Unit) { Chip( label = { if (isLoading) { CircularProgressIndicator( modifier = Modifier .fillMaxSize() .wrapContentSize(Alignment.Center) ) } else { Text( text = "Refresh", modifier = Modifier .fillMaxSize() .wrapContentSize(Alignment.Center) ) } }, onClick = { onClick() }, modifier = Modifier .width(intrinsicSize = IntrinsicSize.Max) .padding(32.dp) ) }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
