r/reactjs • • Apr 27 '20

Show /r/reactjs Declarative Magnet Animation w/ Framer Motion

577 Upvotes

21 comments sorted by

30

u/maxs_dev Apr 27 '20 edited Apr 27 '20

Here's the code and demo, happy to answer any questions!

https://variable.app/p/0088wbsgZacahMVEORaY

5

u/davertron Apr 28 '20

This is a neat demo, but not knowing a whole lot about Framer Motion it's hard to get much out of reading the code. It would be awesome if you at least threw some comments in there to describe what's going on.

3

u/maxs_dev Apr 29 '20

Hey, totally understand. I'm thinking it might be more helpful to write an article to go in depth into some of the concepts, for instance there's hidden logic that the motion value used in the x prop is a 2-way binding. Is that something you (or anyone else) would find helpful?

2

u/davertron Apr 29 '20

Yep that would be sweet!

10

u/Mikeytown19 Apr 27 '20

never heard of variable, really slick.

27

u/[deleted] Apr 28 '20 edited Apr 28 '20

That's because it has just launched and this is post is really an ad for Variable and not about the fairly generic animation. The OP is almost certainly the same guy in the "Media Pack" link from Variable's landing page:

https://www.notion.so/maxsteitle/Media-Kit-5c5e79cea25e4c258572fbb883c755ea

and this guy retweeted by Variable's Twitter:

https://twitter.com/MaxSteitle/status/1237391955094454272

I guess he didn't break any rules but full disclosure would have been the right thing to do as Variable is a commercial product.

As for Variable, it looks very neat and focuses on the most important stuff, and is not trying to be a web IDE like Code Sandbox which is going in the wrong direction IMO.

10

u/maxs_dev Apr 28 '20

Hey, sorry about that. I made Variable with a friend to share cool stuff and code together, really just solving our own problem. It's also completely free.

I've been using Framer motion since it came out and thought this would be a helpful example how to use some of the trickier things like motion values, sequencing, transforms, etc. Hopefully it was helpful to some.

Thanks for the feedback, we just wanted a lightweight React editor without the noise.

7

u/[deleted] Apr 28 '20

Hey. No problem, just thought it was odd you talking about it without claiming ownership :-).

It's very cool and I hope it goes on to be successful.

-1

u/blinky-leads Apr 28 '20

Color me pessimistic, but even this comment sounds like an ad. I know native advertising when I see it.

It's also completely free.

For now. Your service looks neat, but it seems very clear you intend to monetize it based on the page with the word 'pricing' in the slug. Be transparent about that.

3

u/maxs_dev Apr 28 '20

Sorry you feel that way, but this is just a side project I made with a friend. About your concern with pricing, we're transparent this is 100% free for personal use and we intend to keep it that way. We plan to have some kind of commercial aspect for professional teams, which is also clearly shown in the link to our pricing you shared.

I mentioned above I've been using Framer motion since it was released and have seen it posted a lot in this sub, so I was inspired to share a more advanced example that could be helpful to the community.

1

u/blinky-leads Apr 28 '20

All of that's great! The problem is you didn't share it that way. Maybe you're a victim of your own success here, but that does not look like an insignificant project. Perhaps I should've said please, but it just doesn't look good. Believe me, I want it to be successful. I wish you the best of luck. Thanks for the Framer example.

3

u/MindOnTheBlink Apr 27 '20

This is impressive. Great job!

As a dev who is currently learning Framer X, I have been wanting give Framer Motion a whirl. How easy it is to adopt if you already have a pretty extensive React background? What were some of your pain points with it?

11

u/maxs_dev Apr 27 '20

I'm actually a Product Designer and started learning to code with OG Framer (it was using coffeescript). Learning React alongside their animation library felt really natural since it's literally just a prop to get things to animate. Some advice is digging into their variants, which can be really powerful as you can orchestrate complex animations a lot easier. Also, if you're using Styled Components you can use Framer Motion alongside like "styled(motion.div)".

5

u/sickcodebruh420 Apr 27 '20

I absolutely fucking love Framer Motion. I use it in React and am currently building my second massive feature that relies on it for a number of heavily orchestrated animations. Works wonderfully with Styled Components, too.

The closest thing to a pain point was and still is thinking about how to build components with animation states in mind, but that’s not unique to Framer Motion. I find that I have to structure some components a bit differently to ensure that the transitions can run in the right order, or I’ll have to position things absolutely when I’d normally just slap flex on a div and let them settle into place. The library itself makes things so easy to express, I’ve never felt limited by it. The fact that it’s written in TypeScript is an added bonus.

7

u/Sphism Apr 27 '20

Always used to make things like this in flash. Fun to do huh.

2

u/StrangeParadigm Apr 27 '20

This is awesome! Thanks for sharing !

2

u/Maguspk Apr 27 '20 edited Apr 28 '20

awesome demo, also my first time seeing variable!

feedback: it’d be awesome if you used a drag handler instead of mouse events, that way you could drag it around on a phone (fun!)

edit: and just to drive home how awesome framer motion is, I was able to make a 2 line edit to get this to behave correctly for touch events (added to the magnet div)

onPan={handleMouseMove}
drag

https://2v4zk.csb.app/

1

u/kenduraghab Apr 28 '20

Awesome 👍👍

0

u/[deleted] Apr 27 '20

Very inspiring .will look at the code and try to understand.

-4

u/[deleted] Apr 28 '20

Cool. Looks useless