Skip to content

Try: Smoother animation for the main content area. - #13831

Closed
jasmussen wants to merge 1 commit into
masterfrom
try/sidebar-animation-polish
Closed

jasmussen wants to merge 1 commit into
masterfrom
try/sidebar-animation-polish

Conversation

@jasmussen

Copy link
Copy Markdown
Contributor

This PR is a followup to #13635 and tries to add additional animation when the sidebar open/closes. Specifically, it now animates the right-margin in lockstep with the sidebar opening and closing. This causes the main body content to animate, just like the sidebar, for a nicer experience.

However in order to be performant, this means we add will-change: transform; to the .edit-post__layout-content`. This is causing an issue with the notices, which will be moot when #13614 gets merged, so this PR is dependant on that landing first.

Secondly, although it's a small PR, the addition of the will-change property is likely going to need a lot of testing so it doesn't cause regressions. Things to look for are absolute, fixed, or sticky position elements and the like. In my own testing, only the notices regressed which as mentioned gets fixed when 13614 lands. But this will still need a lot of eyes.

animation

This PR tries to add additional animation when the sidebar open/closes. Specifically, it now animates the right-margin in lockstep with the sidebar opening and closing. This causes the main body content to animate, just like the sidebar, for a nicer experience.

However in order to be performant, this means we add `will-change: transform;` to the .edit-post__layout-content`. This is causing an issue with the notices, which will be moot when #13614 gets merged, so *this PR is dependant on that landing first*.

Secondly, although it's a small PR, the addition of the will-change property is likely going to need a lot of testing so it doesn't cause regressions. Things to look for are absolute, fixed, or sticky position elements and the like. In my own testing, only the notices regressed which as mentioned gets fixed when 13614 lands. But this will still need a lot of eyes.
@jasmussen jasmussen added the [Status] In Progress Tracking issues with work in progress label Feb 12, 2019
@jasmussen jasmussen self-assigned this Feb 12, 2019
@jasmussen jasmussen added the [Type] Enhancement A suggestion for improvement. label Feb 12, 2019
@kjellr

kjellr commented Feb 12, 2019

Copy link
Copy Markdown
Contributor

When testing this out on smaller posts, this looks great! Really nice and smooth.

I'm seeing performance decrease as the post gets longer though. 😕 Not quite a surprise, but if I test with a 300+ block post (I just duplicated the demo post a bunch of times), the sidebar animates in fine, but the content doesn't animate at all. Instead, there's a bit of a delay, and then it just snaps into place. My guess is that some of the wide/full blocks are causing the bulk of the hiccup, as they need to drastically resize media as the editing area gets smaller.

I also have a general question about using will-change here: All the guidance I've seen recommends that you add will-change shortly before your animation is triggered, and remove it when it's done, to prevent a performance hit. From MDN:

Use sparingly. The normal behavior for optimizations that the browser make is to remove the optimizations as soon as it can and revert back to normal. But adding will-change directly in a stylesheet implies that the targeted elements are always a few moments away from changing and the browser will keep the optimizations for much longer time than it would have otherwise. So it is a good practice to switch will-change on and off on using script code before and after the change occurs.

I'm wondering if we need to be a bit more careful about our use of it here? In general, can we use JS to add and remove that property as needed?

@jasmussen

Copy link
Copy Markdown
Contributor Author

You're absolutely right, will-change is sort of a sensitive thing. Honestly it shouldn't be — it's just a way to tell the browser, hey, render this stuff on the GPU. But in practice as you allude to it has all sorts of side-effects. I'm not sure enabling/disabling it via JS is the way to go, because if it DOES have negative side-effects, those will be visible during the animation, whereas if it doesn't have any side-effects, on the contrary it should just make the whole thing more performant.

But this is also why I pushed this as a separate PR. Sad to hear that it's not performant, and it won't be the end of the world if we can't do this. It's in our new principles: if we can't make it performant, leave it out. Have to walk the walk.

I'm wondering how things such as Google Keep or Google Calendar (which uses the same technique) can make a smooth animation like this, without taking a performance hit? In the case of calendar, the main canvas does resize during the animation. Perhaps there's just overall less on the page? It'd be nice if we were sure we couldn't make it performant, before we close this.

@kjellr

kjellr commented Feb 13, 2019

Copy link
Copy Markdown
Contributor

I'm wondering how things such as Google Keep or Google Calendar (which uses the same technique) can make a smooth animation like this, without taking a performance hit? In the case of calendar, the main canvas does resize during the animation.

Can you share where you see this? The closest thing I can find in Google Calendar is this, but it just pops in with no animation for me:

slide

@jasmussen

Copy link
Copy Markdown
Contributor Author

Ah yes, visit https://keep.google.com/ or https://calendar.google.com/calendar/r and click the hamburger menu.

@kjellr

kjellr commented Feb 13, 2019

Copy link
Copy Markdown
Contributor

Ah cool, thanks. From a quick look, my guess is that they're just dealing with a lot less data. Calendar doesn't show more than one month on the screen at a time (and even then, there are no images involved). Keep does include images, but they don't appear to be resizing the actual content column: it just moves over as necessary. And once the screen gets too small, the sidebar panel slides in over the content, preventing any resize.

@jasmussen

Copy link
Copy Markdown
Contributor Author

Yep. You're right. It has to be fullwide images needing to resize that cause this. Closing this for now then! Thanks so much for taking a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants