mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
fix(core): Scroll listener register failure after unregister (#10368)
This commit is contained in:

committed by
GitHub

parent
f5f4666e04
commit
e4fe276bed
@ -130,10 +130,10 @@ export class ScrollView extends ScrollViewBase {
|
||||
|
||||
protected attachNative() {
|
||||
if (!this.handler) {
|
||||
const that = new WeakRef(this);
|
||||
const viewRef = new WeakRef(this);
|
||||
this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({
|
||||
onScrollChanged: function () {
|
||||
const owner: ScrollView = that.get();
|
||||
const owner: ScrollView = viewRef.get();
|
||||
if (owner) {
|
||||
owner._onScrollChanged();
|
||||
}
|
||||
@ -166,9 +166,13 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
this.nativeViewProtected.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
||||
this.handler = null;
|
||||
protected detachNative() {
|
||||
if (this.handler) {
|
||||
if (this.nativeViewProtected) {
|
||||
this.nativeViewProtected.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
||||
}
|
||||
this.handler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,6 @@ export class ScrollView extends ScrollViewBase {
|
||||
this._setNativeClipToBounds();
|
||||
}
|
||||
|
||||
disposeNativeView() {
|
||||
this.dettachNative();
|
||||
this._delegate = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
_setNativeClipToBounds() {
|
||||
if (!this.nativeViewProtected) {
|
||||
return;
|
||||
@ -70,9 +64,12 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
if (this.nativeViewProtected) {
|
||||
this.nativeViewProtected.delegate = null;
|
||||
protected detachNative() {
|
||||
if (this._delegate) {
|
||||
if (this.nativeViewProtected) {
|
||||
this.nativeViewProtected.delegate = null;
|
||||
}
|
||||
this._delegate = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,9 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
|
||||
|
||||
if (arg === ScrollViewBase.scrollEvent) {
|
||||
this._scrollChangeCount++;
|
||||
this.attach();
|
||||
if (this.nativeViewProtected) {
|
||||
this.attachNative();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,40 +31,35 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
|
||||
super.removeEventListener(arg, callback, thisArg);
|
||||
|
||||
if (arg === ScrollViewBase.scrollEvent) {
|
||||
this._scrollChangeCount--;
|
||||
this.dettach();
|
||||
if (this._scrollChangeCount > 0) {
|
||||
this._scrollChangeCount--;
|
||||
|
||||
if (this.nativeViewProtected && this._scrollChangeCount === 0) {
|
||||
this.detachNative();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@profile
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
|
||||
this.attach();
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
this.dettach();
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
private attach() {
|
||||
if (this._scrollChangeCount > 0 && this.isLoaded) {
|
||||
initNativeView() {
|
||||
super.initNativeView();
|
||||
if (this._scrollChangeCount > 0) {
|
||||
this.attachNative();
|
||||
}
|
||||
}
|
||||
|
||||
private dettach() {
|
||||
if (this._scrollChangeCount === 0 && this.isLoaded) {
|
||||
this.dettachNative();
|
||||
public disposeNativeView() {
|
||||
if (this._scrollChangeCount > 0) {
|
||||
this.detachNative();
|
||||
}
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
protected attachNative() {
|
||||
//
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
protected detachNative() {
|
||||
//
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user