fix(scrollView): ensure scroll element exists for event listeners

Related #6104
This commit is contained in:
Adam Bradley
2016-06-08 22:08:28 -05:00
parent f049521095
commit 1188730f10

View File

@ -132,18 +132,20 @@ export class ScrollView {
this._cb = onScrollCallback;
this._pos = [];
this._el.addEventListener('touchstart', this._start.bind(this));
this._el.addEventListener('touchmove', this._move.bind(this));
this._el.addEventListener('touchend', this._end.bind(this));
this._el.parentElement.classList.add('js-scroll');
if (this._el) {
this._el.addEventListener('touchstart', this._start.bind(this));
this._el.addEventListener('touchmove', this._move.bind(this));
this._el.addEventListener('touchend', this._end.bind(this));
this._el.parentElement.classList.add('js-scroll');
}
return () => {
this._el.removeEventListener('touchstart', this._start.bind(this));
this._el.removeEventListener('touchmove', this._move.bind(this));
this._el.removeEventListener('touchend', this._end.bind(this));
this._el.parentElement.classList.remove('js-scroll');
if (this._el) {
this._el.removeEventListener('touchstart', this._start.bind(this));
this._el.removeEventListener('touchmove', this._move.bind(this));
this._el.removeEventListener('touchend', this._end.bind(this));
this._el.parentElement.classList.remove('js-scroll');
}
};
}