r/reactjs • • Oct 09 '21

How to control the elements with react.js like this video ?

519 Upvotes

63 comments sorted by

199

u/Snapstromegon Oct 09 '21

This animation is great for a trailer video, but in my opinion should never under any circumstances should happen on a real page.

Animation should always serve a purpose to either give direction, feedback or pull focus. And you can't focus on everything. And it's not even like it's giving you one direction to tell you "start looking here", but is jumping all around and has seven different movement directions/types, often multiple in the same container.

I often go by the rule of "if it's hard to animate, you shouldn't do it in the first place" (this refers to the complexity of the constuct to animate, not the code).

33

u/Alngaawy Oct 09 '21

I meant move an element from column to the other .. not this all things

24

u/a9footmidget Oct 09 '21

Drag events and listeners.

Make card draggable. Make columns drop zones.

On dragover, change styles / classes to show the dotted border drop.

On drop, grab element via ref, append it to container element.

Not overly complicated and totally doable without the need for third party libs.

3

u/volivav Oct 09 '21

grab element via ref, append it to container element.

Won't react get confused when it tries to reconcile on the next update?

1

u/toshi_34 Oct 09 '21

There's a drag event!!! I'll try this ad you say..

8

u/SerranoPeps Oct 09 '21

React-grid-layout npm package is good for that sort of thing

4

u/straightouttaireland Oct 09 '21

Not too mobile friendly though

1

u/valtism Oct 10 '21

dnd-kit would be ideal for this. To get the hanging angle on drag you would need to do via ccs using transition and a skew angle.

5

u/kanye_is_a_douche Oct 09 '21

I agree with you in general although there is some room for unobtrusive animated flourishes here and there if done tastefully.

3

u/Snapstromegon Oct 09 '21

I think personally that every animation in an interactive media should serve a purpose and shouldn't be there just to look nice.

In my experiences those "unobstrusive animations" or often either pulling unwanted focus or can be changed into something with a clear purpose.

I mean, having like 5-7 animations on a button alone isn't a problem, if each serves a purpose, but just adding an animation without a interaction purpose is something I seldomly saw working. But that's also just my experience, maybe there are great examples out there, which I just don't know.

2

u/lordpuddingcup Oct 09 '21

I don’t see an issue with this as long as it happens once and then falls back to quick loading maybe via a session variable or cookie etc but that’s just me.

One-off animations don’t annoy me it’s the tiny repetitive ones that slow down using things that drive me nuts

3

u/Snapstromegon Oct 10 '21

Like my human-computer-interaction professor used to say: An animation which a user actively picks out, because he actively spends time waiting for it, is bad, if it's tied to an interaction.

So repetitive animations like a button ripple should be so small and fast, that a user only recognizes them subconsciously.

Also "one-off" animations are something I don't rely on, since there are so many people using incognito or auto clearing modes for their browser (at least among my users and peers), so they'd see it again and again.

171

u/Lil_Jiggly47 Oct 09 '21

To complex drag and drop like in the video i use "react-beautiful-dnd", it's incredible usefull

46

u/straightouttaireland Oct 09 '21

Until you want nested scrolling 😭

30

u/Kyle772 Oct 09 '21

Are you me?

18

u/straightouttaireland Oct 09 '21

And hundreds of others unfortunately!

6

u/iJubag Oct 09 '21

Are there any specific advantages to nested scrolling over just having expandable containers? I’ve always found it to be kind of annoying from a users perspective

13

u/straightouttaireland Oct 09 '21

Having a sticky header per column. Think of the trello app... imagine if that didn't allowed nested scrolling where you can scrolling vertically in a column and also drag a card horizontally.

5

u/dotContent Oct 09 '21

Or displaying draggables as a grid

3

u/kylemh Oct 10 '21

Doesn't nested scrolling work fine? I thought `react-beautiful-dnd` is used for both Trello and Jira.

3

u/straightouttaireland Oct 10 '21

It may be used, but they must have added this feature privately as the repo hasn't been maintained for years.

1

u/straightouttaireland Oct 10 '21

Not on mobile i.e smaller screens

49

u/maddy_0120 Oct 09 '21 edited Oct 10 '21

I blame Dribble for this. All these new UX designers add a lot of unnecessary animations thinking it will look cool on their portfolio.

Then, the clients be like I want that!. It's a coding nightmare.

9

u/amarbuga Oct 09 '21

But the biggest pain is the performance we used framer motion and the performance hit was crazy .

5

u/The5thElephant Oct 10 '21

For in/out animations like this (these are overkill) it’s quite easy to implement in React/Vue with a CSS tool my brother and I built: AnimXYZ.com and the performance is generally quite good thanks to hardware acceleration and not relying on JS request animation frame complexity.

We automatically turn them off if a user has reduced-motion preferences turned on in their OS or browser settings, and we generally suggest using animations subtly to inform the user although there are times it’s nice to have some flashy eye catching motion.

5

u/kecupochren Oct 10 '21

But that's what Dribbble is about. Showcase. For real world, UX optimized solutions there is Behance

-3

u/[deleted] Oct 09 '21

Bruh did you try to code drag and drop and fail? What kind of kanban board from 100 years ago doesn't have DnD?

2

u/maddy_0120 Oct 10 '21

That's not what I'm talking about. I just said that some designers like to add unnecessary animations to their designs.

I did say it's a coding nightmare, but that's just my opinion, cause I'm terrible at CCS.

-1

u/[deleted] Oct 10 '21

Ok but what does those unnecessary animations have to do with this video of a fairly average drag and drop kanban board?

3

u/maddy_0120 Oct 10 '21

It's not the drag and drop that's the problem. Its everything else in the video.

0

u/[deleted] Oct 10 '21

Oh I didn't see the beginning of the video sry

12

u/guyariely Oct 09 '21

for the elements entering the screen - you can use the css animation property and keyframes (animate the transform and opacity).

for reordering the items in the list - react-beautiful-dnd is your best bet

16

u/nahtnam Oct 09 '21

https://dndkit.com/ this is an alternative to react-beautiful-dnd

3

u/Smaktat Oct 09 '21

This seems so good.

1

u/MaggoLive Oct 10 '21

the examples feel so smooth!

1

u/plastix3000 Oct 10 '21

Too many people trying to use the abbreviation 'dnd' and I can't keep up.

  • Do not disturb (original dictionary definition)

  • Dungeons and dragons (the only true dnd)

  • Dan and Dave (how Reddit send to refer to the hack showrunners from game of thrones)

This is the first time I've seen drag and drop

15

u/AcidNoX Oct 09 '21

Most of this can be fairly easily achieved with framer-motion.

There are several different types of animation here so no one is going to be able to answer you question in a single comment.

9

u/[deleted] Oct 09 '21

Framer motion is a beast of a library for animations.

How to take care of the drag and reposition though? Framer does allow dragging. But repositioning perfectly into a grid?

4

u/AcidNoX Oct 09 '21

AnimateSharedLayout should handle the dnd

https://www.framer.com/docs/animate-shared-layout/

1

u/[deleted] Oct 09 '21

Yeah but what about perfectly fitting into the place on its own (snapping)? Can Animate shared layout handle that too? Maybe (for this design), all I would need a flexbox container, and then allow dragging of the boxes.

Am I right?

5

u/AcidNoX Oct 09 '21

Essentially the cards would be represented in state as a 2D array. On drop, you calculate the new position in that 2D array and, as long as the element has the same “layoutId” framer handles the animation

2

u/[deleted] Oct 09 '21

Thanks man. Will try this one out.

How do you suggest recalculating the new position? Mouse events? Framer motion drag event?

2

u/AcidNoX Oct 09 '21

Yeah I’d use onDragEnd from framer

2

u/[deleted] Oct 09 '21

Got it.

2

u/AcidNoX Oct 10 '21

I spent a couple of hours putting a demo together. It turned out to be not quite as easy as I hoped as apparently framer does not yet support "onDragOver" events (https://github.com/framer/motion/issues/538 ).

This meant I had to add some extra code to determine which column the card is intersecting, etc.

Anywho, here's the link: https://codesandbox.io/s/silly-hawking-7jx8w

This is purely a PoC - the code is nowhere near production-ready and I certainly wasn't adhering to best practices etc so please excuse the mess.

Should give you an idea of how you might achieve it though :)

1

u/[deleted] Oct 28 '21

Hey man, good news!

Framer Motion 5 comes with reordering!!

Check this out: https://www.framer.com/docs/reorder/

1

u/jonno11 Oct 10 '21

Goodbye framerate

4

u/thefreymaster Oct 09 '21

Looks like something a designer made on Dribbble

3

u/Amantulsyan35 Oct 09 '21

npm array-move is also ba good alternative

2

u/bleedeleventh Oct 10 '21

I use interact.js for drag and drop events. it has tons of interactive events and might help you

3

u/cyor2345 Oct 09 '21

Anime js ?

2

u/Blackwater_7 Oct 09 '21

my eyes

6

u/NeatBeluga Oct 09 '21

For a presentation, it looks dope. As a tool I would hate the animations.

1

u/kiesoma Oct 10 '21

For the animations, I normally use react-reveal.

Not sure about the drag and drop though :(

1

u/sankalpmukim Oct 10 '21

CSS is hard

1

u/U_WinSome_U_LoseSome Oct 10 '21

REACT-GRID-LAYOUT

1

u/Curtis017 Oct 10 '21

Lots of people recommending ui frameworks or libraries. Not sure of your entire use case, but I’ll throw out that this is “technically“ a built in functionality within most browsers. Just use the “draggable” attribute on the element:

https://www.w3schools.com/tags/att_global_draggable.asp