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() {
(<any>this.nativeViewProtected).menuItemClickListener.owner = null;
if ((<any>this.nativeViewProtected)?.menuItemClickListener) {
(<any>this.nativeViewProtected).menuItemClickListener.owner = null;
}
super.disposeNativeView();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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