diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 0f03b1739..7e27b8e5a 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -57,13 +57,19 @@ function initializeTouchListener(): void { @Interfaces([android.view.View.OnTouchListener]) class TouchListenerImpl extends java.lang.Object implements android.view.View.OnTouchListener { - constructor(private owner: View) { + private owner: WeakRef; + constructor(owner: View) { super(); + this.owner = new WeakRef(owner); + return global.__native(this); } onTouch(view: android.view.View, event: android.view.MotionEvent): boolean { - const owner = this.owner; + const owner = this.owner.get(); + if (!owner) { + return; + } owner.handleGestureTouch(event); let nativeView = owner.nativeViewProtected; @@ -211,7 +217,7 @@ function initializeDialogFragment() { const owner = this.owner; if (owner) { - // Android calls onDestroy before onDismiss. + // Android calls onDestroy before onDismiss. // Make sure we unload first and then call _tearDownUI. if (owner.isLoaded) { owner.callUnloaded(); @@ -298,7 +304,7 @@ export class View extends ViewCommon { let view: View = this; let frameOrTabViewItemFound = false; while (view) { - // when interacting with nested fragments instead of using getSupportFragmentManager + // when interacting with nested fragments instead of using getSupportFragmentManager // we must always use getChildFragmentManager instead; // we have three sources of fragments -- Frame fragments, TabViewItem fragments, and // modal dialog fragments @@ -1026,4 +1032,4 @@ createNativePercentLengthProperty({ createNativePercentLengthProperty({ setter: "_setMinHeightNative", get setPixels() { return org.nativescript.widgets.ViewHelper.setMinHeight } -}); \ No newline at end of file +});