Slide 31
Slide 31 text
var sizeAnimation: Animatable by ..
var targetSize: IntSize? by remember { mutableStateOf(null) }
var offsetAnimation: Animatable by ..
var placementOffset: IntOffset by remember { mutableStateOf(IntOffset.Zero) }
var targetOffset: IntOffset? by remember { mutableStateOf(null) }
LaunchedEffect(Unit) {
launch {
snapshotFlow { targetSize }
.collect { target -> sizeAnimation.animateTo(target, ..) }
}
launch {
snapshotFlow { targetOffset }
.collect { target -> offsetAnimation.animateTo(target, ..) }
}
}
Modifier
.onPlaced { lookaheadScopeCoordinates, layoutCoordinates ->
placementOffset = lookaheadScopeCoordinates
.localPositionOf(layoutCoordinates, Offset.Zero).round()
targetOffset = lookaheadScopeCoordinates
.localLookaheadPositionOf(layoutCoordinates).round()
}
.intermediateLayout { measurable, _, lookaheadSize ->
targetSize = lookaheadSize
val actualSize = sizeAnimation.value
val constraints = Constraints.fixed(actualSize.width, actualSize.height)
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
val (x, y) = offsetAnimation.value - placementOffset
placeable.place(x, y)
}
}
Let’s try
visualising