One example
function defined in the Crane app looks like this
@Composable
private fun tintPeopleUserInput(
transitionState: MutableTransitionState<PeopleUserInputAnimationState>
): State<Color> {
val validColor = MaterialTheme.colors.onSurface
val invalidColor = MaterialTheme.colors.secondary
val transition = updateTransition(transitionState)
return transition.animateColor(
transitionSpec = { tween(durationMillis = 300) }
) {
if (it == Valid) validColor else invalidColor
}
}
Now as I understand it, Compose is smart enough to just handle it perfectly fine if the function looked like this instead
@Composable
private fun tintPeopleUserInput(
transitionState: MutableTransitionState<PeopleUserInputAnimationState>
): Color {
val validColor = MaterialTheme.colors.onSurface
val invalidColor = MaterialTheme.colors.secondary
val transition = updateTransition(transitionState, label = "")
val color by transition.animateColor(
transitionSpec = { tween(durationMillis = 300) }, label = ""
) {
if (it == Valid) validColor else invalidColor
}
return color
}
So why would one ever chose one over the other? If they are functionally equivalent, it feels like the simple non-state return type should be preferable? Are there any guidelines on this?