Dominaezzz
07/18/2021, 12:04 AMval someBoolean = true // this is calculated
val translationSize = 100f // this is calculated
val animatedDelta by animateFloatAsState(if (someBoolean) 0.0f else 1.0f)
val value = if (someBoolean) {
animatedDelta * -translationSize
} else {
(1 - animatedDelta) * translationSize
}
Adam Powell
07/18/2021, 1:31 AMlhwdev
07/18/2021, 7:03 AMgraphicsLayer { /* here! */ }
, it won't trigger recomposition. I would write this:
val animatedDelta by animateFloatAsState(...) // (do not read this in places other than inside graphicsLayer)
Box(Modifier.graphicsLayer { alpha /* or other properties */ = animatedDelta }) {
// maybe put some computations here
}
Maybe using other than graphicsLayer
?Dominaezzz
07/18/2021, 7:58 AMgraphicsLayer(translationY = ...)
instead of graphicsLayer { ... }
. Didn't know the latter was better for recomposition.Dominaezzz
07/18/2021, 8:00 AMDominaezzz
07/18/2021, 8:02 AMval value: Float
if (someOtherBoolean) {
// the code I posted above
} else {
value = 0.0f
}
Modifier.graphicsLayer(translationY = value)
I had it this way so I could snap stuff back into position.Dominaezzz
07/18/2021, 11:22 AMAnimatableState
with the suspend APIs and LaunchedEffect
, it works but it's a frame too slow. So I end up seeing jitter in the UI.Dominaezzz
07/18/2021, 11:27 AMLazyColumn
and I'm animating a swap between two adjacent items. (This is for drag and drop/reordering)
So first I do the swap in the dataset and when the items are composed in their new positions, I translate them to their old positions and then animate them into their new positions.lhwdev
07/18/2021, 12:15 PMDominaezzz
07/18/2021, 12:17 PMDominaezzz
07/18/2021, 12:21 PMAnimatableState
• Before swap, everything is fine.
• Swap happens in data set
• When composing, the item is composed in new position
• Eventually LaunchedEffect
catches up and snaps the translation to the old position
• Then animate into the new positionDominaezzz
07/18/2021, 12:22 PMAnimatableState
.Adam Powell
07/18/2021, 1:48 PManimateFloatAsState
is using the same suspend APIs so there's not something intrinsically different thereDominaezzz
07/18/2021, 1:50 PMDominaezzz
07/18/2021, 2:05 PMDominaezzz
07/18/2021, 2:12 PMAnimatable
https://github.com/Dominaezzz/compose-dnd/compare/animatable?expand=1&ts=4 .Dominaezzz
07/18/2021, 2:13 PMmaster
, the selected item follows smoothly but in the animatable
branch, the selected item jitters when it's moved between other items.Adam Powell
07/18/2021, 2:42 PMCoroutineScope.launch
from composable functions, the scope.launch { translation.snapTo(0f) }
calls in particular are going to be issuesDominaezzz
07/18/2021, 2:55 PMDominaezzz
07/18/2021, 3:04 PMLaunchedEffect
. I think I might need to use the transition API to make this do what I want.Adam Powell
07/18/2021, 3:09 PM