Skip to content

Commit 9fae9c4

Browse files
authored
fix(ios): ScrollView with listeners removed scroll delegate (#10432)
1 parent 2cf166d commit 9fae9c4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/core/ui/scroll-view/scroll-view-common.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,53 @@ import { CoreTypes } from '../../core-types';
99

1010
@CSSType('ScrollView')
1111
export abstract class ScrollViewBase extends ContentView implements ScrollViewDefinition {
12-
private _scrollChangeCount = 0;
1312
public static scrollEvent = 'scroll';
1413

1514
public orientation: CoreTypes.OrientationType;
1615
public scrollBarIndicatorVisible: boolean;
1716
public isScrollEnabled: boolean;
1817

18+
private _addedScrollEvent = false;
19+
1920
public addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any): void {
21+
const hasExistingScrollListeners: boolean = this.hasListeners(ScrollViewBase.scrollEvent);
22+
2023
super.addEventListener(arg, callback, thisArg);
2124

22-
if (arg === ScrollViewBase.scrollEvent) {
23-
this._scrollChangeCount++;
25+
// This indicates that a scroll listener was added for first time
26+
if (!hasExistingScrollListeners && this.hasListeners(ScrollViewBase.scrollEvent)) {
27+
this._addedScrollEvent = true;
28+
2429
if (this.nativeViewProtected) {
2530
this.attachNative();
2631
}
2732
}
2833
}
2934

3035
public removeEventListener(arg: string, callback?: (data: EventData) => void, thisArg?: any): void {
36+
const hasExistingScrollListeners: boolean = this.hasListeners(ScrollViewBase.scrollEvent);
37+
3138
super.removeEventListener(arg, callback, thisArg);
3239

33-
if (arg === ScrollViewBase.scrollEvent) {
34-
if (this._scrollChangeCount > 0) {
35-
this._scrollChangeCount--;
40+
// This indicates that the final scroll listener was removed
41+
if (hasExistingScrollListeners && !this.hasListeners(ScrollViewBase.scrollEvent)) {
42+
this._addedScrollEvent = false;
3643

37-
if (this.nativeViewProtected && this._scrollChangeCount === 0) {
38-
this.detachNative();
39-
}
44+
if (this.nativeViewProtected) {
45+
this.detachNative();
4046
}
4147
}
4248
}
4349

4450
initNativeView() {
4551
super.initNativeView();
46-
if (this._scrollChangeCount > 0) {
52+
if (this._addedScrollEvent) {
4753
this.attachNative();
4854
}
4955
}
5056

5157
public disposeNativeView() {
52-
if (this._scrollChangeCount > 0) {
58+
if (this._addedScrollEvent) {
5359
this.detachNative();
5460
}
5561
super.disposeNativeView();

0 commit comments

Comments
 (0)