fix(modals): application activityBackPressed event not fired for modals (#6261)

This commit is contained in:
Alexander Vakrilov
2018-09-13 16:51:12 +03:00
committed by vakrilov
parent 8a5f73055e
commit 8575c60b13
5 changed files with 54 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
import { android as androidApp, AndroidActivityBackPressedEventData } from "tns-core-modules/application";
import { fromObject, Observable } from "tns-core-modules/data/observable"
let context: Observable;
function activityBackPressedCallback(args: AndroidActivityBackPressedEventData) {
if (context && context.get("shouldCancel")) {
context.set("shouldCancel", false);
context.set("message", "Back-pressed canceled!");
args.cancel = true;
}
}
export function onLoaded(args) {
console.log("back-button modal test loaded");
context = fromObject({
message: "First back-press will be canceled",
shouldCancel: true
});
args.object.bindingContext = context;
if (androidApp) {
androidApp.on("activityBackPressed", activityBackPressedCallback);
}
}
export function onUnloaded(args) {
console.log("back-button modal test unloaded");
if (androidApp) {
androidApp.off("activityBackPressed", activityBackPressedCallback);
}
}

View File

@@ -0,0 +1,4 @@
<StackLayout loaded="onLoaded" unloaded="onUnloaded">
<Label text="{{ message }}" />
<Label text="{{ 'will cancel next back press: ' + shouldCancel }}" />
</StackLayout>