Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring animations #8

Open
rsaccon opened this issue Feb 21, 2019 · 2 comments
Open

Spring animations #8

rsaccon opened this issue Feb 21, 2019 · 2 comments

Comments

@rsaccon
Copy link

rsaccon commented Feb 21, 2019

I added Spring animations to dominator. It is based on they the current react native implementation. For very basic use case it works, see example but it is not well integrated yet with dominator animation, because your current animation code is only targeting timing animations such as easing (defined by a duration). Spring animations are defined by other parameters such as stiffness and damping.

So I have been thinking to generalize the data structures and as a first step replace in your code duration: f64 with an enum which can contain all the parameter of the chosen type of animation:

enum AnimationEnum {
    Timing(f64),  // duration
    Spring(SpringConfig),
   // Decay(f64),  // initial velocity (not implemented yet)
}

pub struct SpringConfig {
    stiffness: f64,
    damping: f64,
    mass: f64,
    initial_velocity: f64,
    overshoot_clamping: bool,
    rest_displacement_threshold: f64,
    rest_speed_threshold: f64,
}

What do think ? Is this something you would be interested in to accept a PR ?

Btw. one observation I made when working with dominator:
If start a new rust project and then just add dominator dependency, it fails to build. Dominator is depending on signals 0.3.0. But only rust-signals latest version 0.3.2 is supposed to work with Rust nightly (I guess). Unfortunately, when I just delete the cargo lock files (dominator and/or dominator examples) and update to latest dependencies, then rebuild fails.

So for a new project with dominator dependency I just copy a cargo lockfile from a dominator example project and all works fine. But I guess that is not the right way to handle it!

I am using rustc 1.33.0-nightly (8e2063d02 2019-01-07)

@Pauan
Copy link
Owner

Pauan commented Feb 21, 2019

This is great, thanks! What's the purpose of the AnimationEnum? As far as I can tell, it isn't needed.

If start a new rust project and then just add dominator dependency, it fails to build.

Thanks for letting me know. There's some breaking changes with Future, so I'm waiting for that to stabilize and then I'll fix futures-signals and dominator.

@rsaccon
Copy link
Author

rsaccon commented Feb 23, 2019

What's the purpose of the AnimationEnum?

Let me try to explain. At the current stage of my Implementation I cannot use SpringAnimations with the original AnimatedSignalVec because a duration is required for animated_map:

pub trait AnimatedSignalVec: SignalVec {
    type Animation;

    fn animated_map<A, F>(self, duration: f64, f: F) -> AnimatedMap<Self, F>
    where
        F: FnMut(Self::Item, Self::Animation) -> A,
        Self: Sized;
}

But I want to provide either a duration (for timing based animations as in your current implementation), a SpringConfiguration for Spring Animations as added in my fork or for the not-implemented-yet DecayAnimation an initial velocity.

An enum containing these structs or types seems to me the easiest way to handle these different initial animation parameters. Does this make sense ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants