Stylianos Gakis
07/26/2022, 9:46 AMvar width by remember { mutableStateOf(0f) } // 0f or 0 or 0.dp not sure what I need yet
var height by remember { mutableStateOf(0f) }
Canvas can get you a size but can only set it on the next frame to the local state as I understand.
Canvas(Modifier.fillMaxSize()) {
width = this.size.width
height = this.size.height
}
OnGloballyPositioned also on the next frame
.onGloballyPositioned { it.size.height | width }
BoxWithConstraints uses subcomposition.
My use case is trying to get the bounds of my Canvas in order to animate something that’s moving inside of it and make sure it’s not going outside.
What other options do I have? Or is getting it from canvas and saving it to a local state the way to go? Also what if I was not using a Canvas anyway, what other alternatives are there?MR3Y
07/26/2022, 11:54 AMModifier.onPlaced {}
should give you the coordinates directly after the parent is placed https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]Samp&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:compose%2F, not sure if there is another API that can give you coordinates earlier than thatStylianos Gakis
07/26/2022, 12:24 PM