Ale Stamato
11/22/2022, 4:32 PMStylianos Gakis
11/22/2022, 5:31 PM+-----------+ +-----------+
| | | |
| | | |
| | | |
| +-------+ | | |
| | 1 | | | |
| +-------+ | --> | |
| +-------+ | | +-------+ |
| | 2 | | | | 1 | |
| +-------+ | | +-------+ |
+-----------+ +-----------+
Now it cross-fades between these two states, but I wanted the button ā1" to fluidly move from the top position to the bottom position.
So moved that item into a movableContent, slapped this modifier on it
fun Modifier.animatePlacementInWindow(): Modifier = composed {
val coroutineScope = rememberCoroutineScope()
var targetOffset by remember { mutableStateOf(IntOffset.Zero) }
var animatable by remember {
mutableStateOf<Animatable<IntOffset, AnimationVector2D>?>(null)
}
this
.onPlaced {
targetOffset = it.positionInWindow().round()
}
.offset {
val anim = animatable ?: Animatable(targetOffset, IntOffset.VectorConverter).also { animatable = it }
if (anim.targetValue != targetOffset) {
coroutineScope.launch {
anim.animateTo(targetOffset, spring(stiffness = Spring.StiffnessVeryLow))
}
}
animatable?.let { it.value - targetOffset } ?: IntOffset.Zero
}
}
with hopes that itād fluidly move to the next position.
It worked, kinda, but I got stopped from this and the fact that having the movableContent going in and out of a SubCompose layout doesnāt work that well.
And no, this didnāt fix it either, this was the first time I tried to use it and couldnāt, then saw on the release notes that it should be fixed with this CL and tried again but alas, it didnāt work that time either š
You can tell I was really finding an excuse to play with the movableContentOf() API but unfortunately didnāt get to ship it yet.
Note: These two states are pure compose state on one destination, not using navigation library for these two states, so I can do this myself without relying on waiting for navigation to support some shape of a āshared element transitionā which would otherwise hopefully make this possible.Ale Stamato
11/22/2022, 6:43 PMchatterInDaSkull
12/07/2022, 7:00 PM