Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
fix(angular2): beta 12 has a change detection bug that misses peekabo…
Browse files Browse the repository at this point in the history
…o scroll

 - add a debounced method that forces the application to tick.
 - this solves an issue where you would scroll down on iOS and the peekaboo header would not update until you interacted with some other component.
  • Loading branch information
justindujardin committed Mar 27, 2016
1 parent 37ec7f8 commit 5a58a05
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ng2-material/components/peekaboo/peekaboo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Directive, OnDestroy, Input} from "angular2/core";
import {Directive, OnDestroy, Input, ApplicationRef} from "angular2/core";
import {Media, MediaListener} from "../../core/util/media";
import {CONST, NumberWrapper, isString} from "angular2/src/facade/lang";
import {debounce} from "../../core/util/util";

/** Different peekaboo actions to apply when active */
@CONST()
Expand Down Expand Up @@ -108,7 +109,7 @@ export class MdPeekaboo implements OnDestroy {
private _mediaListeners: MediaListener[] = [];


constructor(public media: Media) {
constructor(public media: Media, private _app: ApplicationRef) {
window.addEventListener('scroll', this._windowScroll);
MdPeekaboo.SIZES.forEach((size: string) => {
this._watchMediaQuery(size);
Expand Down Expand Up @@ -136,6 +137,9 @@ export class MdPeekaboo implements OnDestroy {
}

private _windowScroll = this.evaluate.bind(this);
private _scrollTick = debounce(() => {
this._app.tick();
}, 100, this);

/**
* Evaluate the current scroll and media breakpoint to determine what scrollTop
Expand Down Expand Up @@ -174,9 +178,11 @@ export class MdPeekaboo implements OnDestroy {
}
if (top >= bp && !this._active) {
this._active = true;
this._scrollTick();
}
else if (top < bp && this._active) {
this._active = false;
this._scrollTick();
}
return bp;
}
Expand Down

0 comments on commit 5a58a05

Please sign in to comment.