Commit 3446a1d9 authored by tommycli's avatar tommycli Committed by Commit bot

Settings Rewrite: Fix subpage animations for direct URLs to subpages.

Previously, if a user navigated to a subpage directly via URL, i.e.
chrome://settings/searchEngines, and then tried to close that subpage,
the animation would not work correctly.

This patch fixes that issue.

BUG=535013

Review URL: https://codereview.chromium.org/1372713002

Cr-Commit-Position: refs/heads/master@{#351189}
parent 76e3b244
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
* @fileoverview * @fileoverview
* Styles used for animating settings subpages. * Styles used for animating settings subpages.
*/ */
neon-animated-pages ::content > * { neon-animated-pages ::content > .iron-selected {
position: static; position: static;
} }
neon-animated-pages ::content > .neon-animating {
position: absolute;
}
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<dom-module id="cr-settings-animated-pages"> <dom-module id="cr-settings-animated-pages">
<link rel="import" type="css" href="settings_animated_pages.css"> <link rel="import" type="css" href="settings_animated_pages.css">
<template> <template>
<neon-animated-pages id="animatedPages" attr-for-selected="id" <neon-animated-pages id="animatedPages" attr-for-selected="id">
selected="main">
<content select="*"></content> <content select="*"></content>
</neon-animated-pages> </neon-animated-pages>
</template> </template>
......
...@@ -58,10 +58,10 @@ Polymer({ ...@@ -58,10 +58,10 @@ Polymer({
var newRouteIsSubpage = newRoute && newRoute.section == this.section; var newRouteIsSubpage = newRoute && newRoute.section == this.section;
var oldRouteIsSubpage = oldRoute && oldRoute.section == this.section; var oldRouteIsSubpage = oldRoute && oldRoute.section == this.section;
// If two routes are at the same level, or if either the new or old route is
// not a subpage, fade in and out.
if (!newRouteIsSubpage || !oldRouteIsSubpage || if (!newRouteIsSubpage || !oldRouteIsSubpage ||
newRoute.subpage.length == oldRoute.subpage.length) { newRoute.subpage.length == oldRoute.subpage.length) {
// If two routes are at the same level, or if either the new or old route
// is not a subpage, fade in and out.
this.$.animatedPages.exitAnimation = 'fade-out-animation'; this.$.animatedPages.exitAnimation = 'fade-out-animation';
this.$.animatedPages.entryAnimation = 'fade-in-animation'; this.$.animatedPages.entryAnimation = 'fade-in-animation';
} else { } else {
...@@ -75,14 +75,8 @@ Polymer({ ...@@ -75,14 +75,8 @@ Polymer({
} }
} }
if (newRouteIsSubpage) { this.$.animatedPages.selected =
// TODO(tommycli): Support paths where the final component carries newRouteIsSubpage ? newRoute.subpage.slice(-1)[0] : '';
// data rather than referring to a specific subpage.
// E.g. internet > internet/known-networks > internet/detail/wifi1_guid
this.$.animatedPages.selected = newRoute.subpage.slice(-1)[0];
} else {
this.$.animatedPages.selected = '';
}
}, },
/** /**
......
...@@ -73,18 +73,36 @@ Polymer({ ...@@ -73,18 +73,36 @@ Polymer({
}, },
/** @private */ /** @private */
expanded_: false, currentRouteChanged_: function(newRoute, oldRoute) {
var newExpanded = newRoute.section == this.section;
var oldExpanded = oldRoute && oldRoute.section == this.section;
var visible = newExpanded || this.currentRoute.section == '';
// If the user navigates directly to a subpage, skip all the animations.
if (!oldRoute) {
if (newExpanded) {
// If we navigate directly to a subpage, skip animations.
this.classList.add('expanded');
this.expandContainer.classList.add('expanded');
} else if (!visible) {
this.hidden = true;
this.$.card.elevation = 0;
}
/** @private */ return;
currentRouteChanged_: function() { }
var expanded = this.currentRoute.section == this.section;
if (expanded != this.expanded_) { if (newExpanded && !oldExpanded) {
this.expanded_ = expanded; this.playAnimation('expand');
this.playAnimation(expanded ? 'expand' : 'collapse'); } else if (oldExpanded && !newExpanded) {
// For contraction, we defer the animation to allow
// settings-animated-pages to reflow the new page correctly.
this.async(function() {
this.playAnimation('collapse');
}.bind(this));
} }
var visible = expanded || this.currentRoute.section == '';
this.$.card.elevation = visible ? 1 : 0; this.$.card.elevation = visible ? 1 : 0;
// Remove 'hidden' class immediately, but defer adding it if we are invisble // Remove 'hidden' class immediately, but defer adding it if we are invisble
...@@ -97,7 +115,7 @@ Polymer({ ...@@ -97,7 +115,7 @@ Polymer({
onExpandAnimationComplete_: function() { onExpandAnimationComplete_: function() {
this.hidden = this.currentRoute.section != '' && this.hidden = this.currentRoute.section != '' &&
this.currentRoute.section != this.section; this.currentRoute.section != this.section;
} },
}); });
Polymer({ Polymer({
...@@ -158,12 +176,12 @@ Polymer({ ...@@ -158,12 +176,12 @@ Polymer({
section.classList.remove('expanded'); section.classList.remove('expanded');
section.expandContainer.classList.remove('expanded'); section.expandContainer.classList.remove('expanded');
// Get the placeholder coordinates before reflowing. var card = section.$.card;
var newRect = section.$.placeholder.getBoundingClientRect(); var newRect = card.getBoundingClientRect();
section.classList.add('neon-animating'); section.classList.add('neon-animating');
this._effect = new KeyframeEffect(section.$.card, [ this._effect = new KeyframeEffect(card, [
{'top': oldRect.top + 'px', 'height': oldRect.height + 'px'}, {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'},
{'top': newRect.top + 'px', 'height': newRect.height + 'px'}, {'top': newRect.top + 'px', 'height': newRect.height + 'px'},
], this.timingFromConfig(config)); ], this.timingFromConfig(config));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment