nan
03/11/2022, 1:59 PMLayout to wrap 2 buttons to create a custom layout, one is OutlinedButton and another is Button. But when I pressing on the Button, the whole custom layout starting flash, it seems the whole Layout keep recompose(I add the log in Layout’s MeasurePolicy lamda and it keeps printing). However, it doesn’t happen if I press on OutLineButton. How could I avoid this?
Thanks.
elevation to null, the problem is gone. But is there method that keep elevation and let Layout works as expected? 🤔Filip Wiesner
03/11/2022, 2:08 PMnan
03/11/2022, 2:30 PM@Composable
fun MyBodyContent() {
MyLayout {
MyButton(onClick = {})
OutlinedButton(onClick = {}) {
Text("OutlinedButton")
}
}
}
@Composable
fun MyButton(
onClick: (() -> Unit)
) {
Button(
onClick = onClick
) {
Text(text = "Button")
}
}
@Composable
fun MyLayout(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
val placeables = measurables.map {
it.measure(constraints)
}
// Track the x co-ord we have placed children up to
var xPosition = 0
val buttonHeight = placeables.first().height
layout(constraints.maxWidth, buttonHeight) {
placeables.forEach { placeable ->
// Position item on the screen
placeable.placeRelative(x = xPosition, y = 0)
// Record the y co-ord placed up to
xPosition += placeable.width
}
}
}
}
When click the Button , something wrong with it, it starts to shift and gonenan
03/11/2022, 2:32 PMnan
03/11/2022, 3:18 PM