Hi folks, I'm trying to figure out how to change t...
# compose
s
Hi folks, I'm trying to figure out how to change text color based on the
initialState
value within
AnimatedContent
. Using the AnimatedContent example from the Android docs which slides number up/down based on the previous
initialState
, I've tried updateTransition along with
animateColor
but I can't find a way to change the text color based on the previous value. Am I missing something obvious here? 🤔
r
Have you tried just changing your underlying state depending on the previous value?
Ie - not relying on the Animation APIs here to help
In your ViewModel or wherever you are doing business logic - looking at the old state to determine what the new state should be.
s
Thanks for the reply. Yep, that will definitely work! But I was trying to figure out if it could be done entirely though Compose with
AnimatedContent
+ something similar for color transition. The ViewModel approach is the fallback though 🙂
r
Not to my knowledge, but maybe @Doris Liu knows some way 🙂 The transitionSpec is for determining how it'll get to the targetState - there is a transitionSpec on animateColor if you want to change the how, but changing the what should probably be calculated in a different way.
d
It'd be useful if the
AnimatedContent
provided the initial/target state in the scope for its content lambda. Please feel free to file a feature request for this. 🙂