| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + import { android as androidApp, AndroidActivityBackPressedEventData } from "tns-core-modules/application"; | ||
| 2 | + import { fromObject, Observable } from "tns-core-modules/data/observable" | ||
| 3 | + | ||
| 4 | + let context: Observable; | ||
| 5 | + function activityBackPressedCallback(args: AndroidActivityBackPressedEventData) { | ||
| 6 | + if (context && context.get("shouldCancel")) { | ||
| 7 | + context.set("shouldCancel", false); | ||
| 8 | + context.set("message", "Back-pressed canceled!"); | ||
| 9 | + args.cancel = true; | ||
| 10 | + } | ||
| 11 | + } | ||
| 12 | + export function onLoaded(args) { | ||
| 13 | + console.log("back-button modal test loaded"); | ||
| 14 | + context = fromObject({ | ||
| 15 | + message: "First back-press will be canceled", | ||
| 16 | + shouldCancel: true | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + args.object.bindingContext = context; | ||
| 20 | + | ||
| 21 | + if (androidApp) { | ||
| 22 | + androidApp.on("activityBackPressed", activityBackPressedCallback); | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + export function onUnloaded(args) { | ||
| 27 | + console.log("back-button modal test unloaded"); | ||
| 28 | + | ||
| 29 | + if (androidApp) { | ||
| 30 | + androidApp.off("activityBackPressed", activityBackPressedCallback); | ||
| 31 | + } | ||
| 32 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + <StackLayout loaded="onLoaded" unloaded="onUnloaded"> | ||
| 2 | + <Label text="{{ message }}" /> | ||
| 3 | + <Label text="{{ 'will cancel next back press: ' + shouldCancel }}" /> | ||
| 4 | + </StackLayout> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,6 +57,15 @@ export function onModalLayout(args: EventData) { | |||
| 57 | 57 | false); | |
| 58 | 58 | } | |
| 59 | 59 | ||
| 60 | + export function onAndroidBackEvents(args: EventData) { | ||
| 61 | + const view = args.object as View; | ||
| 62 | + view.showModal( | ||
| 63 | + "android-back-button/android-back-button-page", | ||
| 64 | + null, | ||
| 65 | + () => console.log("android-back-button modal page layout closed"), | ||
| 66 | + true, true, true); | ||
| 67 | + } | ||
| 68 | + | ||
| 60 | 69 | export function onModalTabView(args: EventData) { | |
| 61 | 70 | const fullscreen = false; | |
| 62 | 71 | const animated = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,5 +19,6 @@ | |||
| 19 | 19 | <Button text="Reset Frame Root View" tap="onFrameRootViewReset" /> | |
| 20 | 20 | <Button text="Reset Tab Root View" tap="onTabRootViewReset" /> | |
| 21 | 21 | <Button text="Reset Layout Root View" tap="onLayoutRootViewReset" /> | |
| 22 | + <Button text="Android Back Btn Events" tap="onAndroidBackEvents" /> | ||
| 22 | 23 | </StackLayout> | |
| 23 | 24 | </Page> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | // Definitions. | |
| 2 | 2 | import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from "."; | |
| 3 | 3 | import { GestureTypes, GestureEventData } from "../../gestures"; | |
| 4 | - import { AndroidActivityBackPressedEventData } from "../../../application"; | ||
| 5 | 4 | // Types. | |
| 6 | 5 | import { | |
| 7 | 6 | ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty, | |
@@ -22,6 +21,7 @@ import { | |||
| 22 | 21 | import { Background, ad as androidBackground } from "../../styling/background"; | |
| 23 | 22 | import { profile } from "../../../profiling"; | |
| 24 | 23 | import { topmost } from "../../frame/frame-stack"; | |
| 24 | + import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application"; | ||
| 25 | 25 | ||
| 26 | 26 | export * from "./view-common"; | |
| 27 | 27 | ||
@@ -107,6 +107,13 @@ function initializeDialogFragment() { | |||
| 107 | 107 | activity: view._context, | |
| 108 | 108 | cancel: false, | |
| 109 | 109 | }; | |
| 110 | + | ||
| 111 | + // Fist fire application.android global event | ||
| 112 | + androidApp.notify(args); | ||
| 113 | + if (args.cancel) { | ||
| 114 | + return; | ||
| 115 | + } | ||
| 116 | + | ||
| 110 | 117 | view.notify(args); | |
| 111 | 118 | ||
| 112 | 119 | if (!args.cancel && !view.onBackPressed()) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments