https://kotlinlang.org logo
e

elye

06/20/2023, 12:32 PM
Find this interesting issue of LazyColumn working with Views with CustomLayoutModifier. The LazyColumn seems to be truncating constraint or size of view beyond more than 60.dp of it's both left and right side. Anyone know why? More code snippet in the thread
The view as below
The code
Copy code
@Composable
fun Greeting() {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        Text("Normal Column")
        Column(
            verticalArrangement = Arrangement.spacedBy(16.dp),
            modifier = Modifier
                .width(150.dp)
                .height(128.dp)
                .background(Color.Yellow)
        ) {
            Spacer(Modifier.height(16.dp))
            CustomLayoutText()
        }
        Text("Lazy Column")
        LazyColumn(
            verticalArrangement = Arrangement.spacedBy(16.dp),
            modifier = Modifier
                .width(150.dp)
                .height(128.dp)
                .background(Color.Yellow)
        ) {
            item {
                Spacer(Modifier.height(16.dp))
            }
            item {
                CustomLayoutText()
            }
        }
    }
}

@Composable
private fun CustomLayoutText() {
    Text("Hello This is a Long text that should fit well",
        modifier = Modifier
            .height(20.dp)
            .layout { measurable, constraints ->
                val placeable =
                    measurable.measure(constraints.offset(180.dp.roundToPx()))
                layout(
                    placeable.width, placeable.height
                ) { placeable.place(0, 0) }
            }
            .background(Color.Gray)
    )
}
When I inspect in InspectorLayout, seems like the view is still there, but just not being visible.