react pose
Created: 2018-06-20 10:49:01 -0700 Modified: 2018-06-21 15:39:11 -0700
Background (reference)
Section titled Background (reference)The full name of this library is Popmotion Pose according to this page. It is a potentially better API than react-spring even though they provide almost exactly the same functionality.
Each individual package in the Popmotion repo is published, but to get the code on your own machine for testing, you need the Popmotion repo. I.e. “npm i react-pose” works, but you’d clone via “https://github.com/Popmotion/popmotion.git”.
The dependency hierarchy is as follows: react-pose → react-pose-core → animated-pose → pose-core
For more information on all of this, read here.
A “pose” is what they call “slots” from react-spring.
To build their examples from their repo, read this page. Note: it is not clear without that page how to get everything running.
React-pose
Section titled React-poseTo find information on react-pose, check out this link specifically. It’s very difficult to find that link from their main page.
Listening per-frame for updated values (reference)
Section titled Listening per-frame for updated values (reference)Use onValueChange, which is an object whose keys are property names and whose values are functions that get called with the property’s new value:
Built-in elements
Section titled Built-in elementsThere are elements like “div”, “circle”, or “button” that correspond to HTML or SVG, but they’re enhanced by Pose. These all show up in supported-elements.ts.
Note that SVG elements need to be placed inside of an SVG (the “DraggableCircle” is taken from here):
Keyframes / sequential animations
Section titled Keyframes / sequential animationsIf you want to run two animations in a row, e.g. “move a div to the right and then color it blue”, you can use Keyframes (which are low level), or you can just use multiple poses and control them via these props. Here’s a quick example (taken from this CodeSandbox that I made):
There are a bunch of things to note:
- If you’re going to animate the “background” or “color” properties changing, you have to use a hex string for the color, not any HTML-compatible string like “red”.
- You can specify transitions like this or like what you see above (which was taken from here).
Using dynamic props in poses/keyframes (reference)
Section titled Using dynamic props in poses/keyframes (reference)Just keep in mind that there’s sort of a bug around this right now; see this troubleshooting note.
Troubleshooting
Section titled Troubleshooting”React does not recognize ____ prop on a DOM element”
Section titled ”React does not recognize ____ prop on a DOM element”There’s an issue about this here. This arises from how they suggest using dynamic props in React:
You’ll then see “React does not recognize the initialFillPercent
prop on a DOM element.”
There’s no easy solution to this for now, but I bundled all of the props into a single object called “transitionprops” (specifically lowercase so as to avoid the warning). This still emits an object into the DOM, but at least there are no warnings:
Then, when making my posed.div, I do this: