@Composable
fun Sample(){
val startPadding = 10.dp
Column {
Text(
text = "sample text",
modifier = Modifier
.paddingFromBaseline(top = 30.dp)
.padding(start = startPadding)
)
Text(
text = "sample text",
modifier = Modifier.padding(start = startPadding)
)
}
}
The above Composable
contains two Text
elements arranged vertically in a Column
. Both Text
elements have the same value set for their start
padding
. The preview is below
something weird happens when the paddingFromBaseline
is set after padding
i.e
@Composable
fun Sample(){
val startPadding = 10.dp
Column {
Text(
text = "sample text",
modifier = Modifier
.padding(start = startPadding)
.paddingFromBaseline(top = 30.dp)
)
Text(
text = "sample text",
modifier = Modifier.padding(start = startPadding)
)
}
}
The padding
before the first Text
seems to have doubled, is this a bug or a feature?
I'm under the impression that the order in which Modifier
methods
are called doesn't matter so the extra padding
shouldn't be there.
I no longer see this issue you mention on the emulator or preview. The
.padding(start=
should add padding to the start. ThepaddingFromBaseline(top=
should add padding from Baseline (ie) you should see top padding getting added. This is the output of your code that I seeNo. The order of the Modifier methods MATTER and you should be concise when you chain your Modifier methods. Refer the official doc