Skip to content
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

Site editor: Rework navigation panel animations #26158

Merged
merged 4 commits into from
Oct 20, 2020

Conversation

david-szabo97
Copy link
Member

@david-szabo97 david-szabo97 commented Oct 15, 2020

Fixes: #26119

Description

Reworks navigation panel animations. Instead of animation it uses transition which also let us have nice closing transition.

Known issues

  • When closing the navigation sidebar, the header toolbar moves to the right by 60px
  • When opening the navigation sidebar, the drawer immediately takes up 60px width and shows a grey outline

How has this been tested?

  • Open site editor
  • Toggle navigation sidebar

Screenshots

ezgif com-gif-maker (2)

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Oct 15, 2020

Size Change: -11 B (0%)

Total Size: 1.2 MB

Filename Size Change
build/edit-site/index.js 21.6 kB +19 B (0%)
build/edit-site/style-rtl.css 3.79 kB -14 B (0%)
build/edit-site/style.css 3.79 kB -16 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.54 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/index.js 8.59 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 130 kB 0 B
build/block-editor/style-rtl.css 11 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/editor-rtl.css 8.93 kB 0 B
build/block-library/editor.css 8.93 kB 0 B
build/block-library/index.js 144 kB 0 B
build/block-library/style-rtl.css 7.69 kB 0 B
build/block-library/style.css 7.69 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.77 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.6 kB 0 B
build/components/index.js 170 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.4 kB 0 B
build/compose/index.js 9.63 kB 0 B
build/core-data/index.js 12.1 kB 0 B
build/data-controls/index.js 684 B 0 B
build/data/index.js 8.63 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 4.43 kB 0 B
build/edit-navigation/index.js 10.8 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.37 kB 0 B
build/edit-post/style.css 6.35 kB 0 B
build/edit-widgets/index.js 26.6 kB 0 B
build/edit-widgets/style-rtl.css 3.09 kB 0 B
build/edit-widgets/style.css 3.09 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/index.js 42.6 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keyboard-shortcuts/index.js 2.39 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.45 kB 0 B
build/primitives/index.js 1.35 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/reusable-blocks/index.js 3.06 kB 0 B
build/rich-text/index.js 13 kB 0 B
build/server-side-render/index.js 2.61 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.75 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.23 kB 0 B

compressed-size-action

@Copons
Copy link
Contributor

Copons commented Oct 15, 2020

I think this might introduce some performance concerns, as the sidebar stays mounted all the times, even when not strictly needed.

I've noticed that we use react-transition-group elsewhere, which would come in handy for us.

I've tried it and it seems it can do the same as the simple transition (bar some CSS adjustments) plus mounting and unmounting as needed.

Example:

// navigation-sidebar/index.js

<CSSTransition
	in={ isNavigationOpen }
	classNames="edit-site-navigation-panel"
	mountOnEnter
	timeout={ 100 }
	unmountOnExit
>
	<NavigationPanel />
</CSSTransition>
// navigation-panel/style.scss

.edit-site-navigation-panel-enter {
	width: 0;
}
.edit-site-navigation-panel-enter-active {
	width: $nav-sidebar-width;
	transition: width 1000ms linear;
}

.edit-site-navigation-panel-exit {
	width: $nav-sidebar-width;
}
.edit-site-navigation-panel-exit-active {
	width: 0;
	transition: width 1000ms linear;
}

I guess we could also keep the CSSTransition in the panel component, by using the isOpen prop as you did.

(Note: the react-transition-group package needs to be installed in edit-site. I've simply copypasted the line "react-transition-group": "^2.9.0" from components/package.json, and clean-installed the whole thing.)


This said, maybe my concerns are unnecessary? 🤔
@vindl do you have an opinion on this?

@david-szabo97
Copy link
Member Author

I don't think keeping it mounted is bad at all. Mounting is much more expensive than keeping it mounted. I don't want to get into the same trouble as we did with the inserter panel. (Opening the inserter drops to 3-8 fps)

@Copons
Copy link
Contributor

Copons commented Oct 15, 2020

I don't think keeping it mounted is bad at all. Mounting is much more expensive than keeping it mounted. I don't want to get into the same trouble as we did with the inserter panel. (Opening the inserter drops to 3-8 fps)

What I'm worried about is that we are unnecessarily fetching templates at first load, when we arguably want to keep things as snappy as possible.

At the same time what you're saying totally makes sense, and I guess eventually the performance issues will be limited by the sidebar pagination/filtering/search/whatever.

@shaunandrews
Copy link
Contributor

This feels very nice.

@david-szabo97
Copy link
Member Author

@Copons Fixed the known issues! It doesn't feel too hacky for me, but I want to know what you think. We can always revert if it's too hacky.

transition: width 100ms linear;
@include reduce-motion("transition");
}

Copy link
Contributor

@Copons Copons Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super into this spacer... 😅

I've tried animating the header padding instead, and imho the result is a good middle ground:

Oct-16-2020 16-16-06

(animation slowed to 10%)

.edit-site-header {
	padding-left: 60px;
	transition: padding-left 100ms linear;
}

body.is-navigation-sidebar-open {
	.edit-site-header {
		padding-left: 0;
		transition: padding-left 20ms linear;
	}
}

I guess we might poke around with the transitions times to find an even sweeter spot for the slide out, but still... What do you think?


Also I wonder if we these header transitions should be moved to the sidebar's styles instead. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my very first idea. I ditched it because it seemed to be impossible to get it perfect 😄 And another reason is, we can't really use anything other than linear transitions. Anyway, if we stick to linear then it's perfect:

slide-in

The slide in transition can be calculated easily. Since our toggle is 60px and our sidebar is 300px. The sidebar takes this time to reach the toggle's width: toggleWidth / sidebarWidth * transitionTime, in our case 60px / 300px * 100ms which is 20ms. We want to shrink padding-left until the sidebar reached the toggle's width. We start the transition at the same time as we start to transition the sidebar (since the toggle is on the left side), for the time it takes to reach the toggle's width:

transition: padding-left 20ms linear;
transition-delay: 0ms;

slide-out

Using the math above, we can calculate when we should start transitioning the padding-left and for how long. Since our sidebar takes 20ms to reach toggle's width, we need to delay the transition by transitionTime - timeToToggleWidth, in our case 100ms - 20ms. It takes 80ms to reach the toggle's width from a fully opened sidebar. If we delay our transition by 80ms, that means we aren't shrinking the padding-left until we reached the toggle's width. Once we reached, we need to run the transition for 20ms, which is how long it takes to go from toggle's width to zero:

transition: padding-left 20ms linear;
transition-delay: 80ms;

Result:

ezgif com-gif-maker (4)

Copy link
Contributor

@Copons Copons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Quick reminder to rebase #26187 after merging this. 🙂

@vindl vindl requested a review from mattwiebe October 19, 2020 13:00
@david-szabo97 david-szabo97 force-pushed the update/navigation-panel-animations branch 2 times, most recently from 83b0517 to bf82194 Compare October 19, 2020 18:14
@jeyip jeyip force-pushed the update/navigation-panel-animations branch from bf82194 to bd29228 Compare October 19, 2020 21:19
@Copons Copons force-pushed the update/navigation-panel-animations branch from bd29228 to ce55683 Compare October 20, 2020 10:40
@Copons
Copy link
Contributor

Copons commented Oct 20, 2020

Rebased again. I'm almost sure the failing e2e are unrelated, but let's see what happens.

@Copons
Copy link
Contributor

Copons commented Oct 20, 2020

@david-szabo97 I'm fairly certain all the failing e2e tests are unrelated to this PR, so just go ahead and merge it. 👍

@david-szabo97 david-szabo97 merged commit e4a9d33 into master Oct 20, 2020
@david-szabo97 david-szabo97 deleted the update/navigation-panel-animations branch October 20, 2020 15:53
@github-actions github-actions bot added this to the Gutenberg 9.3 milestone Oct 20, 2020
@jasmussen
Copy link
Contributor

Cool work here.

As a small request, I would appreciate considering the mobile experience. While the overall template building experience on mobile devices is likely not going to be the best in the near future, at some point it nevertheless needs to be considered, as it is a menu item available to mobile users. The sooner we start testing every PR for it, the easier it will be. A lot of the time it's enough to wrap desktop-specific affordances in a @include break-small() { ... } clause. #26021 takes a good first step.

@Copons
Copy link
Contributor

Copons commented Oct 26, 2020

@jasmussen Thanks for mentioning it!
I remember seeing that PR when it was opened, and somehow mistaken it for an issue... 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site Editor: Navigation Sidebar Sliding Animation
4 participants