fix(core): improve loaded/unloaded handling

This commit is contained in:
Nathan Walker
2023-01-16 11:41:04 -08:00
parent c9e29aa9af
commit 18b911ed84
17 changed files with 57 additions and 28 deletions

View File

@ -177,7 +177,9 @@ export class ActionBar extends ActionBarBase {
} }
public disposeNativeView() { public disposeNativeView() {
if ((<any>this.nativeViewProtected)?.menuItemClickListener) {
(<any>this.nativeViewProtected).menuItemClickListener.owner = null; (<any>this.nativeViewProtected).menuItemClickListener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -95,7 +95,7 @@ export class Button extends ButtonBase {
} }
public disposeNativeView() { public disposeNativeView() {
if (this.nativeViewProtected) { if ((<any>this.nativeViewProtected)?.clickListener) {
(<any>this.nativeViewProtected).clickListener.owner = null; (<any>this.nativeViewProtected).clickListener.owner = null;
} }
super.disposeNativeView(); super.disposeNativeView();

View File

@ -476,7 +476,6 @@ export class View extends ViewCommon {
} }
public disposeNativeView(): void { public disposeNativeView(): void {
super.disposeNativeView();
if (this.touchListenerIsSet) { if (this.touchListenerIsSet) {
this.touchListenerIsSet = false; this.touchListenerIsSet = false;
if (this.nativeViewProtected) { if (this.nativeViewProtected) {
@ -485,9 +484,13 @@ export class View extends ViewCommon {
} }
if (this.layoutChangeListenerIsSet) { if (this.layoutChangeListenerIsSet) {
this.layoutChangeListenerIsSet = false; this.layoutChangeListenerIsSet = false;
if (this.nativeViewProtected) {
this.nativeViewProtected.removeOnLayoutChangeListener(this.layoutChangeListener); this.nativeViewProtected.removeOnLayoutChangeListener(this.layoutChangeListener);
this.layoutChangeListener = null;
} }
} }
super.disposeNativeView();
}
setOnTouchListener() { setOnTouchListener() {
if (this.touchListenerIsSet || !this.nativeViewProtected || !this.hasGestureObservers()) { if (this.touchListenerIsSet || !this.nativeViewProtected || !this.hasGestureObservers()) {

View File

@ -91,7 +91,9 @@ export class DatePicker extends DatePickerBase {
if (this.timePicker) { if (this.timePicker) {
this.timePicker.disposeNativeView(); this.timePicker.disposeNativeView();
} }
if ((<any>this.nativeViewProtected)?.listener) {
(<any>this.nativeViewProtected).listener.owner = null; (<any>this.nativeViewProtected).listener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -67,7 +67,9 @@ export class Image extends ImageBase {
} }
public disposeNativeView() { public disposeNativeView() {
if ((<any>this.nativeViewProtected)?.listener) {
(<any>this.nativeViewProtected).listener.owner = null; (<any>this.nativeViewProtected).listener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -39,13 +39,12 @@ export class Image extends ImageBase {
} }
public disposeNativeView(): void { public disposeNativeView(): void {
super.disposeNativeView();
if (this.nativeViewProtected?.image) { if (this.nativeViewProtected?.image) {
this.nativeViewProtected.image = null; this.nativeViewProtected.image = null;
} }
this.disposeImageSource(); this.disposeImageSource();
super.disposeNativeView();
} }
private setTintColor(value: Color) { private setTintColor(value: Color) {

View File

@ -16,6 +16,7 @@ export class RootLayout extends RootLayoutBase {
super.insertChild(view, atIndex); super.insertChild(view, atIndex);
if (!view.hasGestureObservers()) { if (!view.hasGestureObservers()) {
// block tap events from going through to layers behind the view // block tap events from going through to layers behind the view
if (view.nativeViewProtected) {
view.nativeViewProtected.setOnTouchListener( view.nativeViewProtected.setOnTouchListener(
new android.view.View.OnTouchListener({ new android.view.View.OnTouchListener({
onTouch: function (view, event) { onTouch: function (view, event) {
@ -25,8 +26,9 @@ export class RootLayout extends RootLayoutBase {
); );
} }
} }
}
removeChild(view: View): void { removeChild(view: View): void {
if (view.hasGestureObservers()) { if (view.hasGestureObservers() && view.nativeViewProtected) {
view.nativeViewProtected.setOnTouchListener(null); view.nativeViewProtected.setOnTouchListener(null);
} }
super.removeChild(view); super.removeChild(view);

View File

@ -131,8 +131,12 @@ export class ListPicker extends ListPickerBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView = this.nativeViewProtected; const nativeView = this.nativeViewProtected;
if ((<any>nativeView)?.formatter) {
(<any>nativeView).formatter.owner = null; (<any>nativeView).formatter.owner = null;
}
if ((<any>nativeView)?.valueChangedListener) {
(<any>nativeView).valueChangedListener.owner = null; (<any>nativeView).valueChangedListener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -153,8 +153,12 @@ export class ListView extends ListViewBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView = this.nativeViewProtected; const nativeView = this.nativeViewProtected;
nativeView.setAdapter(null); nativeView.setAdapter(null);
if ((<any>nativeView).itemClickListener) {
(<any>nativeView).itemClickListener.owner = null; (<any>nativeView).itemClickListener.owner = null;
}
if ((<any>nativeView).adapter) {
(<any>nativeView).adapter.owner = null; (<any>nativeView).adapter.owner = null;
}
this.clearRealizedCells(); this.clearRealizedCells();
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -166,8 +166,8 @@ export class ScrollView extends ScrollViewBase {
} }
disposeNativeView() { disposeNativeView() {
super.disposeNativeView();
this.removeNativeListener(); this.removeNativeListener();
super.disposeNativeView();
} }
public _onOrientationChanged() { public _onOrientationChanged() {

View File

@ -50,6 +50,7 @@ export class ScrollView extends ScrollViewBase {
} }
disposeNativeView() { disposeNativeView() {
this.removeNativeListener();
this._delegate = null; this._delegate = null;
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -150,8 +150,12 @@ export class SearchBar extends SearchBarBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView: any = this.nativeViewProtected; const nativeView: any = this.nativeViewProtected;
if (nativeView.closeListener) {
nativeView.closeListener.owner = null; nativeView.closeListener.owner = null;
}
if (nativeView.queryTextListener) {
nativeView.queryTextListener.owner = null; nativeView.queryTextListener.owner = null;
}
this._searchPlate = null; this._searchPlate = null;
this._searchTextView = null; this._searchTextView = null;
super.disposeNativeView(); super.disposeNativeView();

View File

@ -238,7 +238,9 @@ export class SegmentedBar extends SegmentedBarBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView: any = this.nativeViewProtected; const nativeView: any = this.nativeViewProtected;
if (nativeView?.listener) {
nativeView.listener.owner = null; nativeView.listener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -52,7 +52,9 @@ export class Switch extends SwitchBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView: any = this.nativeViewProtected; const nativeView: any = this.nativeViewProtected;
if (nativeView.listener) {
nativeView.listener.owner = null; nativeView.listener.owner = null;
}
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -350,8 +350,8 @@ export class TabViewItem extends TabViewItemBase {
} }
public disposeNativeView(): void { public disposeNativeView(): void {
super.disposeNativeView();
(<TabViewItemDefinition>this).canBeLoaded = false; (<TabViewItemDefinition>this).canBeLoaded = false;
super.disposeNativeView();
} }
public createNativeView() { public createNativeView() {

View File

@ -123,10 +123,12 @@ export class WebView extends WebViewBase {
public disposeNativeView() { public disposeNativeView() {
const nativeView = this.nativeViewProtected; const nativeView = this.nativeViewProtected;
if (nativeView) { if (nativeView) {
if ((<any>nativeView).client) {
(<any>nativeView).client.owner = null;
}
nativeView.destroy(); nativeView.destroy();
} }
(<any>nativeView).client.owner = null;
super.disposeNativeView(); super.disposeNativeView();
} }

View File

@ -208,10 +208,10 @@ export class WebView extends WebViewBase {
} }
disposeNativeView() { disposeNativeView() {
super.disposeNativeView();
this._delegate = null; this._delegate = null;
this._scrollDelegate = null; this._scrollDelegate = null;
this._uiDelegate = null; this._uiDelegate = null;
super.disposeNativeView();
} }
// @ts-ignore // @ts-ignore