Animating All Layout
caution
Transition.allLayout()
may cause unexpected transitions because it adds transitions to ALL components present in the layout tree, which may include components higher than the target component in the hierarchy. Please use it carefully.
The Transition.allLayout()
method enables all layout changes to be easily animated without having to assign transitionKey
s to all components:
useTransition(Transition.allLayout().animator(ANIMATOR))
The following key points apply to Transition.allLayout()
:
- Targets
AnimatedProperty.X
,Y
,HEIGHT
andWIDTH
of all components present in the layout tree. - Can be used to define Change transitions only. To define the Appear and Disappear transitions,
transitionKey
s still need to be assigned. - Could be used as a part of more complex choreography.
The following example can be found in Litho Sample App -> API Demos -> Animated Badge
:
useTransition(
Transition.parallel<Transition.BaseTransitionUnitsBuilder>(
Transition.allLayout().animator(ANIMATOR),
Transition.create(Transition.TransitionKeyType.GLOBAL, TRANSITION_KEY_TEXT)
.animate(AnimatedProperties.WIDTH)
.appearFrom(0f)
.disappearTo(0f)
.animator(ANIMATOR)
.animate(AnimatedProperties.ALPHA)
.appearFrom(0f)
.disappearTo(0f)
.animator(ANIMATOR)))
The following animation shows the above 'AnimatedBadge' in action.