Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat(top-app-bar): Update top app bar scrolling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
williamernest committed Mar 28, 2018
1 parent f7d3a46 commit f78e542
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions packages/mdc-top-app-bar/standard/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class MDCTopAppBarFoundation extends MDCTopAppBarBaseFoundation {
*/
this.wasDocked_ = true;

/**
* isDockedShowing is used to indicate if the top app bar is docked in the fully
* shown position.
* @private {boolean}
*/
this.isDockedShowing = true;

/**
* Variable for current scroll position of the top app bar
* @private {number}
Expand Down Expand Up @@ -94,23 +101,29 @@ class MDCTopAppBarFoundation extends MDCTopAppBarBaseFoundation {
* @private
*/
checkForUpdate_() {
const partiallyShowing = this.currentAppBarScrollPosition_ < 0
&& this.currentAppBarScrollPosition_ > -this.topAppBarHeight_;
const offscreenBoundaryTop = -this.topAppBarHeight_;
const hasAnyPixelsOffscreen = this.currentAppBarScrollPosition_ < 0;
const hasAnyPixelsOnscreen = this.currentAppBarScrollPosition_ > offscreenBoundaryTop;
const partiallyShowing = hasAnyPixelsOffscreen && hasAnyPixelsOnscreen;

if (this.wasDocked_) {
// If it was previously already docked but now is partially showing, it's no longer docked.
if (partiallyShowing) {
this.wasDocked_ = false;
return true;
}
// If it was previously already docked but now is partially showing, it's no longer docked.
if (partiallyShowing) {
this.wasDocked_ = false;
} else {
// If it's not previously docked and not partially showing, it just became docked.
if (!partiallyShowing) {
// Not previously docked and not partially showing, it's now docked.
if (!this.wasDocked_) {
this.wasDocked_ = true;
return true;
} else {
// If it was previously docked and now it's docked the opposite way, update the DOM.
if (this.isDockedShowing !== hasAnyPixelsOnscreen) {
this.isDockedShowing = hasAnyPixelsOnscreen;
return true;
}
}
return true;
}
return false;

return partiallyShowing;
}

/**
Expand Down Expand Up @@ -150,7 +163,7 @@ class MDCTopAppBarFoundation extends MDCTopAppBarBaseFoundation {
this.currentAppBarScrollPosition_ = -this.topAppBarHeight_;
}

requestAnimationFrame(() => this.moveTopAppBar_());
this.moveTopAppBar_();
}
}

Expand Down

0 comments on commit f78e542

Please sign in to comment.