If you set tap gesture on a button parent (e.g. some layout for example) and set tap handler on the button and click the button there is a chance to execute navigation with clear history. This will remove current fragment and will clear the button listener owner. Still android will fire the click handler and we will throw an exception. (#4898)

Fix https://github.com/NativeScript/NativeScript/issues/4897
This commit is contained in:
Hristo Hristov
2017-09-28 09:17:54 +03:00
committed by GitHub
parent d64bb1976e
commit 9b52bbcd29

View File

@ -9,7 +9,7 @@ import { TouchGestureEventData, GestureTypes, TouchAction } from "../gestures";
export * from "./button-common"; export * from "./button-common";
interface ClickListener { interface ClickListener {
new (owner: Button): android.view.View.OnClickListener; new(owner: Button): android.view.View.OnClickListener;
} }
let ClickListener: ClickListener; let ClickListener: ClickListener;
@ -29,7 +29,10 @@ function initializeClickListener(): void {
} }
public onClick(v: android.view.View): void { public onClick(v: android.view.View): void {
this.owner._emit(ButtonBase.tapEvent); const owner = this.owner;
if (owner) {
owner._emit(ButtonBase.tapEvent);
}
} }
} }