Piotr Prus
06/13/2023, 12:31 PMonPlaced
lambda. That way every time my view appears on the screen it animates nicely. Now, I need to make exit animation, but I believe there is no modifier that I could use for it, right? The only think that comes to my mind is DisposableEffect that will run when child view exit the composition.Doris Liu
06/13/2023, 4:33 PMPiotr Prus
06/13/2023, 4:41 PMDoris Liu
06/13/2023, 6:00 PMDrawScope
on its way out.Piotr Prus
06/13/2023, 6:22 PMfun Modifier.animatePlacement(
durationMillis: Int = 200,
easing: Easing = EaseOutBack,
offsetPercent: Float = 0.5f,
): Modifier = composed {
val scope = rememberCoroutineScope()
val anim = remember { Animatable(1f) }
var dimension by remember { mutableStateOf(0) }
this
.onPlaced {
dimension = (it.size.height * offsetPercent).toInt()
if (anim.value == 1f) {
scope.launch {
anim.animateTo(
targetValue = 0f,
animationSpec = tween(durationMillis, easing = easing)
)
}
}
}
.offset {
IntOffset(
x = 0,
y = (dimension * anim.value).toInt()
)
}
.alpha(1f - anim.value)
}
Caching feels like overenginiring. We will use that to a lot of different composables. It might be a text, button, image, or the whole column with video, images, etc
so ideally I would like to have something like:
.onRemove {
scope.launch {
anim.animateTo(targetValue = 1f, animSpec = tween(durationMillis, easing = easing))
}
}
Doris Liu
06/13/2023, 7:01 PMPiotr Prus
06/14/2023, 7:58 AMmgrazianodecastro
06/22/2023, 12:57 PM