What is the proper way to animate text changes? `...
# compose
y
What is the proper way to animate text changes?
Crossfade
cannot be use inside Row scope ((
d
Crossfade
should work in RowScope, although it won't automatically change size for you. What is your use case?
2
Consider adding
Modifier.animateContentSize
to either
Crossfade
or
Row
if you need the size change to be animated.
y
@Doris Liu Yep. You are right. My mistake. It is wrong import of Crossfade. Should be
Crossfade(targetState = …)
z
@Doris Liu I am trying to use crossfade to animate text change but the second text, being shorter then the first, makes a jump to be centered at the end of the animation, i would like it to be centered just like the first text. How can i prevent that?
d
Sorry for the late reply. You'd need to specify content alignment for the text such that they fade in/out while being center aligned.
Crossfade
doesn't currently support that, but you could consider using
AnimatedContent
and leverage the
contentAlignment
parameter.
z
Oh ok cool, thank you i will try that!🙏