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

Way to preserve existing transform properties (rotations) ? #156

Open
lawrensylvan opened this issue May 26, 2021 · 2 comments
Open

Way to preserve existing transform properties (rotations) ? #156

lawrensylvan opened this issue May 26, 2021 · 2 comments

Comments

@lawrensylvan
Copy link

Hi and first of all thank you for this awesome library.

During my experience with this library, it seems that I am unable to achieve a simple thing : animate an element for which I assigned a preexisting transform: rotate(...) css property. It seems react-flip-toolkit is replacing the transform property with a new transform with the necessary translations but get rids of the transform ?

Ideally I would like to be able to animate rotations (support for such animations is not mentioned in the doc of this library, nor it is for the other FLIP libraries). But even if I'm not able to animate them, I would like to be able to keep them with their existing rotation value.

If you can confirm that the behaviour I'm describing should not happen, then I can dig deeper and provide a POC example of the problem.
Thanks a lot.

@dudo
Copy link

dudo commented Sep 16, 2021

I think I have a similar question. I'm moving an element from 1 parent to another. With no rotation, this works beautifully. My use case is a playing card game, so think a draw pile and some players spaced out in a circle of sorts.

Anyway, I created a little demo of what this looks like:

https://codesandbox.io/s/wizardly-tree-gzxzy?file=/src/App.js

Any thoughts @aholachek ?

@tkriplean
Copy link
Contributor

I also have this issue. You can work around it though, fairly easily. Probably way too late for you both, but perhaps useful to others later.

react-flip-toolkit exposes the spring method that is used under the hood to update your animation over time. So you can just instantiate the spring directly, and use it to update your transform.

var my_el = (...) // some HTML element you want to apply a transform to

ReactFlipToolkit.spring({
  config: 'gentle',
  values: {
    scale: [1, 1.5]
  },
  onUpdate: ({scale}) => {
    return my_el.style.transform = `scale(${scale})`;
  },
  onComplete: () => {
    return title_text.style.transform = null;
  }
});

Usually though you'll already have a Flipper instantiated. You can use the onSpringUpdate callback to get the current spring value and update your transform accordingly.

Here's some super ugly pseudo pseudo code to give a hint:

Flipper
  spring: "gentle",

  (...)

  Flipped
    (...)
    onSpringUpdate: (val) => { 
      var start = 1;
      var target = 2;
      var my_el = (...) // some HTML element you want to apply a transform to, scaling between 1 and 2
      my_el.style.transform = `scale(${start + val * (target - start)})`;
     }

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

3 participants