mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(core): improve loaded/unloaded handling to be stable and consistent (#10170)
This commit is contained in:
@@ -118,17 +118,10 @@ export class ScrollView extends ScrollViewBase {
|
||||
this.nativeViewProtected.setId(this._androidViewId);
|
||||
}
|
||||
|
||||
public _onOrientationChanged() {
|
||||
if (this.nativeViewProtected) {
|
||||
const parent = this.parent;
|
||||
if (parent) {
|
||||
parent._removeView(this);
|
||||
parent._addView(this);
|
||||
}
|
||||
protected addNativeListener() {
|
||||
if (!this.nativeViewProtected) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected attachNative() {
|
||||
const that = new WeakRef(this);
|
||||
if (this.orientation === 'vertical') {
|
||||
this.scrollChangeHandler = new androidx.core.widget.NestedScrollView.OnScrollChangeListener({
|
||||
@@ -144,7 +137,7 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
},
|
||||
});
|
||||
this.nativeView.setOnScrollChangeListener(this.scrollChangeHandler);
|
||||
this.nativeViewProtected.setOnScrollChangeListener(this.scrollChangeHandler);
|
||||
} else {
|
||||
this.handler = new android.view.ViewTreeObserver.OnScrollChangedListener({
|
||||
onScrollChanged: function () {
|
||||
@@ -158,6 +151,35 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected removeNativeListener() {
|
||||
if (!this.nativeViewProtected) {
|
||||
return;
|
||||
}
|
||||
if (this.handler) {
|
||||
this.nativeViewProtected?.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
||||
this.handler = null;
|
||||
}
|
||||
if (this.scrollChangeHandler) {
|
||||
this.nativeView?.setOnScrollChangeListener(null);
|
||||
this.scrollChangeHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
disposeNativeView() {
|
||||
super.disposeNativeView();
|
||||
this.removeNativeListener();
|
||||
}
|
||||
|
||||
public _onOrientationChanged() {
|
||||
if (this.nativeViewProtected) {
|
||||
const parent = this.parent;
|
||||
if (parent) {
|
||||
parent._removeView(this);
|
||||
parent._addView(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _lastScrollX = -1;
|
||||
private _lastScrollY = -1;
|
||||
private _onScrollChanged() {
|
||||
@@ -179,17 +201,6 @@ export class ScrollView extends ScrollViewBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected dettachNative() {
|
||||
if (this.handler) {
|
||||
this.nativeViewProtected?.getViewTreeObserver().removeOnScrollChangedListener(this.handler);
|
||||
this.handler = null;
|
||||
}
|
||||
if (this.scrollChangeHandler) {
|
||||
this.nativeView?.setOnScrollChangeListener(null);
|
||||
this.scrollChangeHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView.prototype.recycleNativeView = 'never';
|
||||
|
||||
Reference in New Issue
Block a user