robercoding
07/06/2023, 7:43 AMfillMaxWidth
modifier should not be an option nor should be allowed.
I still give the chance to the developer to pass a Modifier
to the button, so it opens the door for him to apply that fillMaxWidth
.
Does anyone know if there’s a way to force a button to use wrapContentWidth
or “_remove_” fillMaxWidth
option?Stylianos Gakis
07/06/2023, 7:48 AMwrapContentWidth
after you apply the modifier incoming to your composable. It would make for some super weird debugging sessions though if you forget that you’ve done that 😄robercoding
07/06/2023, 7:54 AM@Composable
fun ButtonSmall(
modifier: Modifier = Modifier,
text: String,
) {
Box(
modifier.border(1.dp, Color.Black).wrapContentWidth(),
contentAlignment = Alignment.Center
) {
Text(text = "text")
}
}
By using it ButtonSmall(Modifier.fillMaxWidth(), text)
It still applies fillMaxWidth
modifier because border fills the entire width.
I’ve also tried to set the border after wrapContentWidth()
Modifier but doesn’t seem to make an effectStylianos Gakis
07/06/2023, 7:56 AMBox(Modifier.size(200.dp).border(1.dp, Color.Red)) {
SmallButton(Modifier.fillMaxWidth())
}
And then
@Composable
fun SmallButton(modifier: Modifier = Modifier) {
Box(
modifier.wrapContentWidth(Alignment.Start).width(80.dp).height(40.dp).border(1.dp, Color.Blue),
) {
Text("H")
}
}
And this gives this outputStylianos Gakis
07/06/2023, 7:57 AMStylianos Gakis
07/06/2023, 7:57 AMBox(Modifier.size(200.dp).border(1.dp, Color.Red)) {
ButtonSmall(Modifier.fillMaxWidth(), "H")
}
and
@Composable
fun ButtonSmall(
modifier: Modifier = Modifier,
text: String,
) {
Box(
modifier.wrapContentWidth().border(1.dp, Color.Black),
contentAlignment = Alignment.Center
) {
Text(text = "text")
}
}
Does indeed also wrap the content widthrobercoding
07/06/2023, 7:57 AMStylianos Gakis
07/06/2023, 7:57 AMwrapContentWidth
after you’ve wrapped, where do you want the content to be alignedStylianos Gakis
07/06/2023, 7:58 AMwrapContentWidth(Alignment.Start)
it will output thisrobercoding
07/06/2023, 7:58 AMrobercoding
07/06/2023, 7:59 AMStylianos Gakis
07/06/2023, 7:59 AM