-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Implement a block reordering animation #16065
Conversation
reset: resetAnimation, | ||
config: { mass: 5, tension: 2000, friction: 200 }, | ||
immediate: prefersReducedMotion, | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This animation needs to be documented a bit (as not so simple :) )
return ( | ||
<animated.div | ||
ref={ ref } | ||
className={ classnames( 'editor-block-list__block-animated-container', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new container for each block. We could probably consider whether it's possible to reuse the same block container.
This is really nice. Impressive work. Lovely to see the reduced motion mixin doing its thing here. GIF: Note that the framerate is not super accurate in that GIF, it's much smoother in real life. However there's one issue which happens if you rapidly click the move buttons in fast succession. What I imagine happens here is that the previous animation did not finish before the new destination is set, so it stutters when you do this. We'll have to find a way to address that. Animation can never be blocking, i.e. you should never have to wait for an animation to complete before you can take an additional action. This is the case now — you can click fast to move. Just noting this principle because throttling the clicks is not how we can fix the jumpiness. Is there a way the new y coordinate can be set, mid-animation and without overriding the existing y coordinate? I.e. if you rapidly click the animation continues unabated but is suddenly just faster? |
That's already the case, I think the issue is different. Still trying to understand exactly what's happening (as it's very hard to notice in my computer), but if I'm not mistaken, I fear this is not really solvable. The way the animation works at the moment is: 1- User clicks move I think the issue might be that the fact that we actually move the block and restore its position can be noticed somewhere even if we do it instantaneously. |
Soo cool. Thanks for that! Just one worry: doesn't the performance suffer from it? |
If all other solution ideas fall short, perhaps a plan b would be to not animate at all in case the movers are clicked very rapidly. One would imagine that in most cases they are used more slowly and not incessantly clicked as in my testing, so turning animation off in that edge case would probably be fine. |
@SchneiderSam I didn't measure yet but I don't think it would suffer that much. If I notice degradations, we might decide to enable it for small/medium posts (less than500 blocks for instance) |
@jasmussen can you describe what's the issue you're seeing when clicking quickly? |
So if I understand this correctly, as a plugin developer I cannot disable animations for my custom post type? We have some customizations where blocks can be freely positioned using drag and drop, so re-ordering with animations like this would not quite work. |
Curious to learn more about this and why it wouldn't work? (it works for floats for instance) |
It's hard to capture in low framerate GIFs, but I'll record a video next time I can. Basically when you rapidly click the movers, faster than the duration of the animation, I'm seeing what can best be described as jumpiness, tearing, and blinking. |
@youknowriad Happy to tell you more about it on Slack. I just briefly tested it and I think it's not relevant for our project as the blocks are positioned within the block list using
I have definitely noticed that too in my quick testing, although I was not able to reliably trigger it. But the animation was suddenly super fast and moving at like 2x speed. |
I pushed a small tweak that I think makes the animation (quick clicks) a bit smoother. Can you confirm? |
Actually I can. I don't know what you did, but I can no longer reproduce the rather stark stuttering and flickering I saw previously. Here's a video where I'm SUPER STRESSING it. I'm clicking so fast my mouse is about to explode: https://cloudup.com/cziNUXxGNcM Yes, it's slliiiiightly choppy when clicking so fast, but well within the boundaries of what's acceptable. Honestly, all good on my account, now! 👍 👍 And for posterity: this animation follows the animation guidelines we have in place for Gutenberg, notably:
|
It seems react-spring should work on react-native, but pinging @Tug since he's working on porting BlockList to work on gutenberg-mobile. |
I noticed a small issue with "Drag & Drop". It seems that the CSS transform applied to the animated wrapper alters the position of the draggable element. (To be able to inspect, you can comment the content of this function https://github.com/WordPress/gutenberg/blob/master/packages/components/src/draggable/index.js#L36) cc @jasmussen @nosolosw if you have ideas on how we can make the draggable position work in this situation. |
Not quite deep enough in the code to know how to help. Is it a bit of CSS that makes it not work? |
I'm going to land this to have it at least a few days in master before the release. |
41ee739
to
3279e11
Compare
y: 0, | ||
}, | ||
reset: resetAnimation, | ||
config: { mass: 5, tension: 2000, friction: 200 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely satisfied with this set yet, but we can tweak it later.
Thanks all for your help on this one. |
* | ||
* @type {boolean} | ||
*/ | ||
const IS_IE = window.navigator.userAgent.indexOf( 'Trident' ) >= 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads up that this line breaks the mobile app.
I created a PR on gutenberg-mobile side to solve it: wordpress-mobile/gutenberg-mobile#1195
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry about that. Should we maybe create a custom version of useReducedMotion
that always return "true" on mobile? Is there an equivalent to prefers-reduced-motion
in mobile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the equivalent landed on 0.60 which was just released: facebook/react-native#23839
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, let's add the equivalent hook once we upgrade to 0.60
@youknowriad @mtias This seems to have added motion as well on typing. Is this by intention? I don't see any discussion around it. It feels a bit weird to move the blocks on Even if this is the desired experience (I find it a bit annoying):
Could we disable it when the user is typing? |
The animation is based on the "block list order" change (additions, removals and reordering). There's no easy way to distinguish the different type of "block additions". We can decide to only apply the animation if the block length stays consistent (reordering) but personally, I do find it useful in the other cases as well. |
@youknowriad I agree if you manually insert a new block. But this is different. |
In theory, the transform is only applied while moving though? |
@youknowriad Doesn't look like it. It's there on page load. |
@ellatrix @BenjaminZekavica can any of you create an issue about this so we don't forget about it. It seems we can remove the transform once the x,y,z equal 0 (no animation)? |
More details on this post https://matiasventura.com/post/using-motion-to-express-change/
This is not completely ready, but feedback would be appreciated already.
Testing instructions