From c73952f364dd76c0c65f20fe11247b9245cb80fd Mon Sep 17 00:00:00 2001 From: DimitrisRK <55595100+DimitrisRK@users.noreply.github.com> Date: Sat, 13 Jun 2020 23:46:57 +0300 Subject: [PATCH] feat(android): Implementing 'onBackPressed' for frame-root (#8634) Useful for meddling with tab-navigated apps. Co-authored-by: Dimitris - Rafail Katsampas --- nativescript-core/ui/frame/frame.android.ts | 24 ++++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/nativescript-core/ui/frame/frame.android.ts b/nativescript-core/ui/frame/frame.android.ts index e8f798f28a..f4c217cf67 100644 --- a/nativescript-core/ui/frame/frame.android.ts +++ b/nativescript-core/ui/frame/frame.android.ts @@ -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 = { - eventName: "activityBackPressed", - object: view, - activity: activity, - cancel: false, - }; - view.notify(viewArgs); + + const viewArgs = { + 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) {