Fudge
09/04/2021, 2:39 PMLayout
? the use case is to animate a component moving from one part of the screen to another.Halil Ozercan
09/04/2021, 3:23 PMadjpd
09/04/2021, 3:23 PMadjpd
09/04/2021, 3:26 PMFudge
09/04/2021, 3:52 PMWhat do you mean by absolute layout position? Do you mean the position relative to window? Relative to parent?Relative to root or window, I will compare the position using a
LayoutCoordinates
which has boundsInWindow()
and boundsInRoot
, so window will be good.Fudge
09/04/2021, 3:54 PMwas thinking about constraint layout:That was my first attempt but it is too limiting. I can't reliably set the velocity of the animation.
If you had a box layout, perhaps setting the offsets would give you positions to which you could animate towards.what do you mean?
Fudge
09/04/2021, 3:59 PM@Composable
fun Hack(content: @Composable () -> Unit) {
var coords: LayoutCoordinates? by remember{ mutableStateOf(null)}
Layout(content = content, measurePolicy = { measureables, constraints ->
if(coords != null){
// Use coords
} else layout(constraints.maxWidth, constraints.maxHeight) {}
}, modifier = Modifier.onGloballyPositioned { coords = it })
}