fix(core): improve loaded/unloaded handling to be stable and consistent (#10170)

This commit is contained in:
Nathan Walker
2023-01-15 19:49:28 -08:00
committed by GitHub
parent a69a9d6921
commit c9e29aa9af
12 changed files with 121 additions and 166 deletions

View File

@@ -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';