https://kotlinlang.org logo
#compose
Title
# compose
a

Adriano Celentano

09/28/2020, 10:02 AM
Is this a bug or is there a reason why my preview looks different than my emulator ?
Copy code
@Composable
fun ModifierLayoutDrawing(
) {
    Canvas(modifier = Modifier
        .fillMaxHeight()
        .fillMaxWidth()
        .background(Color.Green)
        .moveDraw()
        ,
        onDraw = {
            drawCircle(color = Color.Blue, radius = 200f)
        }
    )
}

@Preview(showBackground = true)
@Composable
fun layoutPreview() {
    ModifierLayoutDrawing()
}

fun Modifier.moveDraw(): Modifier {
    return layout { measurable, constraints ->
        val place = measurable.measure(constraints = constraints)

        layout(constraints.maxWidth, constraints.maxHeight) {
            place.placeRelative(100, 0)
        }
    }
}
e

Elias

09/28/2020, 10:46 AM
Try to remove the moveDraw modifier, see if that interferes with the whole canvas. Could be that you are moving everything.
j

Javier

09/28/2020, 10:59 AM
API 29
🙏 1