Skip to main content

Animation

Struct Animation 

Source
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

Source

pub fn timing(value: &AnimatedValue, to: f32, timing: Timing) -> Self

value moving to to as timing says.

Source

pub fn spring(value: &AnimatedValue, to: f32, spring: Spring) -> Self

value springing to to.

Source

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).

Source

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.

Source

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).

Source

pub fn delay(ms: f32) -> Self

A wait of ms milliseconds (in a sequence).

Source

pub fn sequence(animations: impl IntoIterator<Item = Animation>) -> Self

animations one after the other; it stops at the first that is stopped.

Source

pub fn parallel(animations: impl IntoIterator<Item = Animation>) -> Self

animations all at once; one stopped stops the others (see Self::stop_together).

Source

pub fn stagger(ms: f32, animations: impl IntoIterator<Item = Animation>) -> Self

animations all at once, each starting ms milliseconds after the one before.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn stop(&self)

Stops its run where it is (the run ends false).

Source

pub fn reset(&self)

Stops its run (which ends false) and puts its values back where they were when it last started.

Trait Implementations§

Source§

impl Clone for Animation

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Animation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Animation

§

impl !Send for Animation

§

impl !Sync for Animation

§

impl !UnwindSafe for Animation

§

impl Forget for Animation

§

impl Freeze for Animation
where *const RcInner<Composed> is !null: Freeze, PhantomData<RcInner<Composed>>: Freeze,

§

impl Move for Animation

§

impl Unpin for Animation
where Rc<Composed>: Unpin,

§

impl UnsafeUnpin for Animation
where *const RcInner<Composed> is !null: UnsafeUnpin, PhantomData<RcInner<Composed>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.