Skip to content

Commit

Permalink
feat(android): Implementing 'onBackPressed' for frame-root (#8634)
Browse files Browse the repository at this point in the history
Useful for meddling with tab-navigated apps.

Co-authored-by: Dimitris - Rafail Katsampas <katsampasdr@gmail.com>
  • Loading branch information
CatchABus and CatchABus committed Jun 13, 2020
1 parent 3198f92 commit c73952f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions nativescript-core/ui/frame/frame.android.ts
Expand Up @@ -1221,20 +1221,18 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {

const view = this._rootView;
let callSuper = false;
if (view instanceof Frame) {
callSuper = !FrameBase.goBack();
} else {
const viewArgs = <application.AndroidActivityBackPressedEventData>{
eventName: "activityBackPressed",
object: view,
activity: activity,
cancel: false,
};
view.notify(viewArgs);

const viewArgs = <application.AndroidActivityBackPressedEventData>{
eventName: "activityBackPressed",
object: view,
activity: activity,
cancel: false,
};
view.notify(viewArgs);

if (!viewArgs.cancel && !view.onBackPressed()) {
callSuper = true;
}
// In the case of Frame, use this callback only if it was overridden, since the original will cause navigation issues
if (!viewArgs.cancel && (view.onBackPressed === Frame.prototype.onBackPressed || !view.onBackPressed())) {
callSuper = view instanceof Frame ? !FrameBase.goBack() : true;
}

if (callSuper) {
Expand Down

0 comments on commit c73952f

Please sign in to comment.