Skip to content

Commit 26d10c4

Browse files
committed
fix(scroll): scroll issues in UIWebView
fixes #11081 fixes #10976 fixes #10966 fixes #10936 fixes #11051 fixes #10889
1 parent 0b440ed commit 26d10c4

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/components/content/content.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export class Content extends Ion implements OnDestroy, AfterViewInit {
349349
) {
350350
super(config, elementRef, renderer, 'content');
351351

352-
let enableScrollListener = this.enableScrollListener.bind(this);
352+
const enableScrollListener = () => this._scroll.enableEvents();
353353
this.ionScroll.onSubscribe = enableScrollListener;
354354
this.ionScrollStart.onSubscribe = enableScrollListener;
355355
this.ionScrollEnd.onSubscribe = enableScrollListener;
@@ -359,12 +359,7 @@ export class Content extends Ion implements OnDestroy, AfterViewInit {
359359
this._imgRndBfr = config.getNumber('imgRenderBuffer', 400);
360360
this._imgVelMax = config.getNumber('imgVelocityMax', 3);
361361

362-
// use JS scrolling for iOS UIWebView
363-
// goal is to completely remove this when iOS
364-
// fully supports scroll events
365-
// listen to JS scroll events
366-
const jsScroll = config.getBoolean('virtualScrollEventAssist');
367-
this._scroll = new ScrollView(_app, _plt, _dom, jsScroll);
362+
this._scroll = new ScrollView(_app, _plt, _dom);
368363

369364
while (navCtrl) {
370365
if (isTabs(<any>navCtrl)) {
@@ -431,8 +426,8 @@ export class Content extends Ion implements OnDestroy, AfterViewInit {
431426
/**
432427
* @hidden
433428
*/
434-
enableScrollListener() {
435-
this._scroll.eventsEnabled = true;
429+
enableJsScroll() {
430+
this._scroll.enableJsScroll(this._cTop, this._cBottom);
436431
}
437432

438433
/**

src/components/virtual-scroll/virtual-scroll.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,14 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
706706
private _listeners() {
707707
assert(!this._scrollSub, '_listeners was already called');
708708
if (!this._scrollSub) {
709+
if (this._config.getBoolean('virtualScrollEventAssist')) {
710+
// use JS scrolling for iOS UIWebView
711+
// goal is to completely remove this when iOS
712+
// fully supports scroll events
713+
// listen to JS scroll events
714+
this._content.enableJsScroll();
715+
}
716+
709717
this._resizeSub = this._plt.resize.subscribe(this.resize.bind(this));
710718
this._scrollSub = this._content.ionScroll.subscribe(this.scrollUpdate.bind(this));
711719
this._scrollEndSub = this._content.ionScrollEnd.subscribe(this.scrollEnd.bind(this));

src/util/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function setupEvents(plt: Platform, dom: DomController): Events {
137137
let contentEle = <any>el.closest('.scroll-content');
138138
if (contentEle) {
139139
var style = contentEle.style;
140-
var scroll = new ScrollView(null, plt, dom, false);
140+
var scroll = new ScrollView(null, plt, dom);
141141
scroll._el = contentEle;
142142
// We need to stop scrolling if it's happening and scroll up
143143

src/util/scroll-view.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ export class ScrollView {
1313
onScroll: (ev: ScrollEvent) => void;
1414
onScrollEnd: (ev: ScrollEvent) => void;
1515
initialized: boolean = false;
16-
eventsEnabled: boolean = false;
17-
contentTop: number;
18-
contentBottom: number;
19-
2016
_el: HTMLElement;
17+
18+
19+
private _eventsEnabled = false;
2120
private _js: boolean;
2221
private _t: number = 0;
2322
private _l: number = 0;
@@ -28,10 +27,8 @@ export class ScrollView {
2827
constructor(
2928
private _app: App,
3029
private _plt: Platform,
31-
private _dom: DomController,
32-
virtualScrollEventAssist: boolean
30+
private _dom: DomController
3331
) {
34-
this._js = virtualScrollEventAssist;
3532
this.ev = {
3633
timeStamp: 0,
3734
scrollTop: 0,
@@ -57,19 +54,20 @@ export class ScrollView {
5754
init(ele: HTMLElement, contentTop: number, contentBottom: number) {
5855
assert(ele, 'scroll-view, element can not be null');
5956
this._el = ele;
60-
this.contentTop = contentTop;
61-
this.contentBottom = contentBottom;
62-
6357
if (!this.initialized) {
6458
this.initialized = true;
6559
if (this._js) {
66-
this.enableJsScroll();
60+
this.enableJsScroll(contentTop, contentBottom);
6761
} else {
6862
this.enableNativeScrolling();
6963
}
7064
}
7165
}
7266

67+
enableEvents() {
68+
this._eventsEnabled = true;
69+
}
70+
7371
private enableNativeScrolling() {
7472
assert(this.onScrollStart, 'onScrollStart is not defined');
7573
assert(this.onScroll, 'onScroll is not defined');
@@ -91,7 +89,7 @@ export class ScrollView {
9189
self._app.setScrolling();
9290

9391
// if events are disabled, we do nothing
94-
if (!self.eventsEnabled) {
92+
if (!self._eventsEnabled) {
9593
return;
9694
}
9795

@@ -200,7 +198,7 @@ export class ScrollView {
200198
* inertia then this can be burned to the ground. iOS's more modern
201199
* WKWebView does not have this issue, only UIWebView does.
202200
*/
203-
enableJsScroll() {
201+
enableJsScroll(contentTop: number, contentBottom: number) {
204202
const self = this;
205203
self._js = true;
206204
const ele = self._el;
@@ -219,7 +217,7 @@ export class ScrollView {
219217
function setMax() {
220218
if (!max) {
221219
// ******** DOM READ ****************
222-
max = ele.scrollHeight - ele.parentElement.offsetHeight + self.contentTop + self.contentBottom;
220+
max = ele.scrollHeight - ele.parentElement.offsetHeight + contentTop + contentBottom;
223221
}
224222
};
225223

0 commit comments

Comments
 (0)