-
Notifications
You must be signed in to change notification settings - Fork 7
Base Classes
Base classes are used to wrap Android animation APIs (more specifically ViewPropertyAnimator
) in RxJava2 syntax and provide you with a generic way to define animations. This page goes through each of those classes and explains their role in the library.
Animation
class holds parameters for a single animation. It is immutable and it's used for holding animation parameters before they're passed to the ViewPropertyAnimator
once the animation needs to start. It can hold all parameters that a ViewPropertyAnimator
can receive (view, translation, scale, rotation, duration, etc.)
The only way to create the Animation
object is to use the AnimationBuilder
class.
AnimationBuilder
does what it says - builds Animation
object. The way to use it is to call AnimationBuilder.for(view)
with a view that you want to animate passed in. After that you can append animation properties same as you would do for ViewPropertyAnimator
. Once you're done, call .build()
to create the Animation
instance. Here's a sample code:
Animation a = AnimationBuilder.forView(someView)
.alpha(0.5f)
.duration(300L)
.interpolator(new LinearInterpolator())
.build();
This is where we bring Android animations to the reactive world. AnimationCompletable
is the extension of RxJava2 Completable, but adapted to running animations.
The features that it provides compared to the normal Completable
is running the specified animation once subscribed to, as well as stoping the animation once disposed. On top of that, you can specify actions to be executed at a particular point in the animation, such as before, when started, when finished or when canceled.
You can create AnimationCompetable
by providing the Animation
to run once subscribed to:
Animation a = AnimationBuilder.forView(someView)
.alpha(0.5f)
.duration(300L)
.interpolator(new LinearInterpolator())
.build();
AnimationCompletable ac = new AnimationCompletable(a);
Animation
class also has toCompletable()
method which you can use to conveniently get AnimationCompletable
object from Animation
:
AnimationCompletable ac = AnimationBuilder.forView(someView)
...
.build()
.toCompletable();
Or even more conveniently:
AnimationCompletable ac = AnimationBuilder.forView(someView)
...
.buildCompletable();
To see how to finally run animations, check the next section: Running the Animations