What is the newest way of positioning a composable...
# compose
r
What is the newest way of positioning a composable at an exact pixel position on the screen. It seems
Copy code
Modifier
    .offset(x = { offset.x }, y = { offset.y })
has been removed from
alpha09
l
I just ran into this myself. The deprecation message says:
Please use offset with lambda parameters instead
but it's not in the library
r
@Adam Powell What do you think about this?
a
Modifier.offset { IntOffset(...) }
looks like the
replaceWith
on the old method was stale
r
Copy code
var boxPosition by remember { mutableStateOf(Offset.Zero) }

Box(
    modifier = Modifier
        .fillMaxSize()
) {
    Box(
        modifier = Modifier
            .dragGestureFilter(dragObserver = object : DragObserver {
                override fun onDrag(dragDistance: Offset): Offset {
                    boxPosition += dragDistance

                    return dragDistance
                }
            })
            .offset {
                IntOffset(boxPosition.x.toInt(), boxPosition.y.toInt())
            }
            .background(color = Color.Black)
            .preferredSize(100.dp)
    )
}
Thx. In this code snippet, the drag observer rarely get's called. It was working fine on alpha08 @Adam Powell
a
Please don't @-mention me personally on every question in here, there are others who can answer them too and I don't need that many notifications 🙂
😂 5