Skip to main content

FloatingActionButtonAnimator

Trait FloatingActionButtonAnimator 

Source
pub trait FloatingActionButtonAnimator: Debug + 'static {
    // Required methods
    fn get_offset(&self, begin: Offset, end: Offset, progress: f64) -> Offset;
    fn get_scale_animation(
        &self,
        app: &mut App,
        parent: AnimationRef<f64>,
    ) -> AnimationRef<f64>;
    fn get_rotation_animation(
        &self,
        app: &mut App,
        parent: AnimationRef<f64>,
    ) -> AnimationRef<f64>;

    // Provided method
    fn get_animation_restart(&self, previous_value: f64) -> f64 { ... }
}
Expand description

Provider of animations to move the FloatingActionButton between FloatingActionButtonLocations.

The Scaffold uses Scaffold.floatingActionButtonAnimator to define:

  • The Offset of the FloatingActionButton between the old and new FloatingActionButtonLocations as part of the transition animation.
  • An Animation to scale the FloatingActionButton during the transition.
  • An Animation to rotate the FloatingActionButton during the transition.
  • Where to start a new animation from if an animation is interrupted.

See also:

  • FloatingActionButton, which is a circular button typically shown in the bottom right corner of the app.
  • FloatingActionButtonLocation, which the Scaffold uses to place the Scaffold.floatingActionButton within the Scaffold’s layout.

Required Methods§

Source

fn get_offset(&self, begin: Offset, end: Offset, progress: f64) -> Offset

Gets the FloatingActionButton’s position relative to the origin of the Scaffold based on progress.

begin is the Offset provided by the previous FloatingActionButtonLocation.

end is the Offset provided by the new FloatingActionButtonLocation.

progress is the current progress of the transition animation. When progress is 0.0, the returned Offset should be equal to begin. when progress is 1.0, the returned Offset should be equal to end.

Source

fn get_scale_animation( &self, app: &mut App, parent: AnimationRef<f64>, ) -> AnimationRef<f64>

Animates the scale of the FloatingActionButton.

The animation should both start and end with a value of 1.0.

For example, to create an animation that linearly scales out and then back in, you could join animations that pass each other with a TrainHoppingAnimation.

Source

fn get_rotation_animation( &self, app: &mut App, parent: AnimationRef<f64>, ) -> AnimationRef<f64>

Animates the rotation of Scaffold.floatingActionButton.

The animation should both start and end with a value of 0.0 or 1.0.

The animation values are a fraction of a full circle, with 0.0 and 1.0 corresponding to 0 and 360 degrees, while 0.5 corresponds to 180 degrees.

For example, to create a rotation animation that rotates the FloatingActionButton through a full circle, drive a Tween from 0.0 to 1.0 with parent.

Provided Methods§

Source

fn get_animation_restart(&self, previous_value: f64) -> f64

Gets the progress value to restart a motion animation from when the animation is interrupted.

previous_value is the value of the animation before it was interrupted.

The restart of the animation will affect all three parts of the motion animation: offset animation, scale animation, and rotation animation.

An interruption triggers if the Scaffold is given a new FloatingActionButtonLocation while it is still animating a transition between two previous FloatingActionButtonLocations.

A sensible default is usually 0.0, which is the same as restarting the animation from the beginning, regardless of the original state of the animation.

Implementations§

Source§

impl dyn FloatingActionButtonAnimator

Source

pub fn scaling() -> FloatingActionButtonAnimatorRef

Moves the FloatingActionButton by scaling out and then in at a new FloatingActionButtonLocation.

This animator shrinks the FloatingActionButton down until it disappears, then grows it back to full size at its new FloatingActionButtonLocation.

This is the default FloatingActionButton motion animation.

Source

pub fn no_animation() -> FloatingActionButtonAnimatorRef

Creates an instance of FloatingActionButtonAnimator where the FloatingActionButton does not animate on entrance and exit when FloatingActionButtonLocation is shown or hidden and when transitioning between FloatingActionButtonLocations.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§