onStep callback for Motion
See original GitHub issueI’m curious how maintainers would feel about adding a callback for each step (more or less calling an optional callback each time the render
function of Motion
is run). We use Motion
at my work and have found ourselves in a situation where onStep
(or something like that) would be really helpful.
Please let me know if this is something we’re open to. I’d be happy to do the work myself. If it’s a no go, I’m happy to fork.
Cheers!
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Difference between event handlers and callbacks
A callback is procedure you pass as an argument to another procedure. ... Event Handlers on the other hand operate at one step...
Read more >1 User Interaction
Two other important mouse callbacks are the “motion” function and the “passive motion” ... but let's take it one step at a time....
Read more >Step-by-Step: Motion Commander - Bitcraze
Here we will go through step-by-step how to make your crazyflie move based on a motion script. For the first part of this...
Read more >Python library for interfacing with Motion Blinds - GitHub
Blind device ; "blind_1.Jog_down()", -, -, Close the blind/move the blind one step down ; "blind_1.Register_callback("1", func), id, callback, string, function ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nkbt Just to add to @berrtech 's question. Do you have a preferred strategy for dealing with cases where the UI state gets out of sync with <Motion> between renders? It would be nice to be able to set the starting value of the animation on any desired render after a component is mounted.
Is the defaultStyle prop intended to handle cases like this? Because in my case where new scroll events are triggered by user input - setting defaultStyle to the current scroll position of the element doesn’t help because Motion ignores it as mentioned in the docs.
My current non-ideal work-around is to force an extra render of Motion before the animation to ensure Motion’s starting point is in sync with the UI.
So - it sees that an auto-scroll event has been triggered - and calls setState to set the value of motionStyle to the current scrollTop value of the element. No animation happens because it’s not using a spring.
But now that Motion has the new starting point - we still need to trigger the animation somehow. But I’ve used up the props change caused by the user click - so there is nothing to trigger the next render. So the only thing I’ve been able to come up with is to use the following:
So - after the render to sync the UI with Motion - calling setState in componentDidUpdate with the desired spring triggers another render which does the animation. Using the prevRenderType flag prevents an infinite regress.
This works - but setting state in componentDidUpdate is generally frowned upon. Plus it uses up an extra render.
Would be keen to hear if anyone has come up with another solution.
This is what we do in one place to do smooth scrolling of a component