More Ways to Define Transitions
@State Arguments
Litho allows @OnCreateTransition methods to take @State arguments if the Transition definition should take value of the state into account.
note
In order to make this happen, the framework needs to postpone collection of Transitions until MountState (always on UI thread), while normally this would be done on LayoutState (which may be processed on a background thread).
@Prop Diff<T> and @State Diff<T>
If your transitions should depend not only on the actual (updated) value of a @Prop or a @State, but rather ont the value change, you could use a generic Diff for arguments, so you get access to both previous and next @State/@Prop values.
Here's how we could change one of our samples to only animate expanding, but not collapsing.
@OnUpdateStateWithTransition
To define transitions that should run conditionally under certain circumstances, you can use @OnUpdateStateWithTranstion method.
It works as regular @OnUpdateState methods, but also returns Transition that should be run whenever the method was invoked.
Another implementation for the above sample using @OnUpdateStateWithTransition may look like this: