Zoltan Demant
11/25/2021, 4:37 PMtransition.AnimatedContent
block sometimes takes 500-1000 ms to execute. Is this a bug, or am I doing something wrong? š§µšAnimatedContent
itself which is super-slow, and it happens when the content passed in has a lot of data, e.g. in this case a list with ~300 items.
val transition = stack
.last()
.let { top ->
updateTransition(
targetState = BackStackState(
key = Compatible.findKey(top),
content = top,
size = size
),
label = null
)
}
transition.AnimatedContent(
contentKey = BackStackState::key,
transitionSpec = {
contentTransform(
difference = targetState.size - initialState.size
)
},
content = { state ->
stateKeeper.SavedState(
key = state.key,
content = {
Render(state.content)
}
)
}
)
private fun contentTransform(
difference: Int
): ContentTransform {
return when {
difference >= 0 -> {
ContentTransform(
targetContentEnter = slideInVertically(
initialOffsetY = { height -> height },
animationSpec = SlideSpec
),
initialContentExit = fadeOut(
animationSpec = FadeSpec
),
targetContentZIndex = 1f
)
}
else -> {
ContentTransform(
targetContentEnter = fadeIn(
animationSpec = FadeSpec
),
initialContentExit = slideOutVertically(
targetOffsetY = { height -> height },
animationSpec = SlideSpec,
)
)
}
}
}
@Immutable
private data class BackStackState(
val content: Any,
val key: String,
val size: Int
)
content
from targetState fixes it, but how am I then to know which content to render in the content block of AnimatedContent?Zach Klippenstein (he/him) [MOD]
11/25/2021, 7:53 PMZoltan Demant
11/26/2021, 6:31 AM() -> Any
block. Not sure if thats a good idea in practice, or is it? Im really looking to transition screens from A -> B, rather than animate whenever A/B themselves change.