pub struct Animation(/* private fields */);Expand description
A composed animation (TS: Animated.timing / spring / decay /
sequence / parallel / stagger / delay / loop): a tree of
steps over animated values, run on the UI thread, each step starting at
the exact end of the one before (no round trip to the engine between
steps).
Build it once (in the view, captured by the listeners that run it) and
run it any number of times: Self::start runs it (stopping a run of
it going on) and returns its AnimationEnd, Self::stop stops it
where it is, Self::reset stops it and puts its values back where
they were when it last started. Clones are the same animation; building a group from
animations makes a new one (its parts are copied in). It holds the nodes
of its values while it lives (values whose owner is gone are left
out), wherever it is kept.
let jump = Animation::sequence([
Animation::timing(&y, -36.0, Timing::new(220.0, Easing::EaseOut)),
Animation::spring(&y, 0.0, Spring::default()),
]);
view().on_press(move || {
let end = jump.start();
})Implementations§
Source§impl Animation
impl Animation
Sourcepub fn timing(value: &AnimatedValue, to: f32, timing: Timing) -> Self
pub fn timing(value: &AnimatedValue, to: f32, timing: Timing) -> Self
value moving to to as timing says.
Sourcepub fn spring(value: &AnimatedValue, to: f32, spring: Spring) -> Self
pub fn spring(value: &AnimatedValue, to: f32, spring: Spring) -> Self
value springing to to.
Sourcepub fn decay(
value: &AnimatedValue,
velocity: Option<f32>,
deceleration: f32,
) -> Self
pub fn decay( value: &AnimatedValue, velocity: Option<f32>, deceleration: f32, ) -> Self
value gliding from velocity (per second; None: the current
one), slowing down by deceleration per millisecond (0.998: a
fling).
Sourcepub fn decay_within(
value: &AnimatedValue,
velocity: Option<f32>,
deceleration: f32,
(min, max): (f32, f32),
bounce: f32,
) -> Self
pub fn decay_within( value: &AnimatedValue, velocity: Option<f32>, deceleration: f32, (min, max): (f32, f32), bounce: f32, ) -> Self
Like Self::decay, within min..=max: it stops at a bound, or
bounces back from it keeping bounce (0..1) of its speed.
Sourcepub fn keyframes(
value: &AnimatedValue,
frames: impl IntoIterator<Item = Keyframe>,
timing: KeyframeTiming,
) -> Self
pub fn keyframes( value: &AnimatedValue, frames: impl IntoIterator<Item = Keyframe>, timing: KeyframeTiming, ) -> Self
value through frames, as CSS keyframes play (TS:
Animated.keyframes): offsets spread as the Web Animations API
spreads them, an easing per segment, iterations, a direction and a
delay (KeyframeTiming).
Sourcepub fn sequence(animations: impl IntoIterator<Item = Animation>) -> Self
pub fn sequence(animations: impl IntoIterator<Item = Animation>) -> Self
animations one after the other; it stops at the first that is
stopped.
Sourcepub fn parallel(animations: impl IntoIterator<Item = Animation>) -> Self
pub fn parallel(animations: impl IntoIterator<Item = Animation>) -> Self
animations all at once; one stopped stops the others (see
Self::stop_together).
Sourcepub fn stagger(ms: f32, animations: impl IntoIterator<Item = Animation>) -> Self
pub fn stagger(ms: f32, animations: impl IntoIterator<Item = Animation>) -> Self
animations all at once, each starting ms milliseconds after the
one before.
Sourcepub fn stagger_from(
ms: f32,
from: StaggerFrom,
animations: impl IntoIterator<Item = Animation>,
) -> Self
pub fn stagger_from( ms: f32, from: StaggerFrom, animations: impl IntoIterator<Item = Animation>, ) -> Self
animations all at once, each starting ms milliseconds after the
one before, counted from from (TS: Animated.stagger(ms, list, { from })): from the center, a list ripples out from its middle.
Sourcepub fn looped(self, iterations: Option<u32>) -> Self
pub fn looped(self, iterations: Option<u32>) -> Self
This animation over and over: iterations times, or until stopped
with None; its values go back to where they were before each run
(see Self::reset_before_iteration).
Sourcepub fn stop_together(self, stop_together: bool) -> Self
pub fn stop_together(self, stop_together: bool) -> Self
For a group made with Self::parallel or Self::stagger:
whether one of its animations stopped stops the others (by
default it does). Other animations stay as they are.
Sourcepub fn reset_before_iteration(self, reset: bool) -> Self
pub fn reset_before_iteration(self, reset: bool) -> Self
For a loop made with Self::looped: whether its values go back
to where they were before each run (by default they do). Other
animations stay as they are.
Sourcepub fn start(&self) -> AnimationEnd
pub fn start(&self) -> AnimationEnd
Runs it, stopping a run of it going on (which ends false). It
runs either way: await the end in a task to follow it up, or drop
it. An animation of no values (only delays) has nothing to run on
and ends at once.