FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(modals): application activityBackPressed event not fired for modals by vakrilov · Pull Request #6261 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (3) .xml  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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);
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<StackLayout loaded="onLoaded" unloaded="onUnloaded">
<Label text="{{ message }}" />
<Label text="{{ 'will cancel next back press: ' + shouldCancel }}" />
</StackLayout>
9 changes: 9 additions & 0 deletions e2e/modal-navigation/app/home/home-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export function onModalLayout(args: EventData) {
false);
}

export function onAndroidBackEvents(args: EventData) {
const view = args.object as View;
view.showModal(
"android-back-button/android-back-button-page",
null,
() => console.log("android-back-button modal page layout closed"),
true, true, true);
}

export function onModalTabView(args: EventData) {
const fullscreen = false;
const animated = false;
Expand Down
1 change: 1 addition & 0 deletions e2e/modal-navigation/app/home/home-page.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<Button text="Reset Frame Root View" tap="onFrameRootViewReset" />
<Button text="Reset Tab Root View" tap="onTabRootViewReset" />
<Button text="Reset Layout Root View" tap="onLayoutRootViewReset" />
<Button text="Android Back Btn Events" tap="onAndroidBackEvents" />
</StackLayout>
</Page>
9 changes: 8 additions & 1 deletion tns-core-modules/ui/core/view/view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Definitions.
import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
import { GestureTypes, GestureEventData } from "../../gestures";
import { AndroidActivityBackPressedEventData } from "../../../application";
// Types.
import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
Expand All @@ -22,6 +21,7 @@ import {
import { Background, ad as androidBackground } from "../../styling/background";
import { profile } from "../../../profiling";
import { topmost } from "../../frame/frame-stack";
import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application";

export * from "./view-common";

Expand Down Expand Up @@ -112,6 +112,13 @@ function initializeDialogFragment() {
activity: view._context,
cancel: false,
};

// Fist fire application.android global event
androidApp.notify(args);
if (args.cancel) {
return;
}

view.notify(args);

if (!args.cancel && !view.onBackPressed()) {
Expand Down

Back | FazBrowse Home | New Git URL