From cf8dcfa40cd65d1bdcb8ad3edb1c4a1eea179c3d Mon Sep 17 00:00:00 2001 From: Martin Yankov Date: Wed, 14 Mar 2018 18:15:05 +0200 Subject: [PATCH] feat(view): expose method for android back override (#5537) Expose method on View class onBackPressed(). Third party controls like RadSideDrawer can use this method to override the default Android back button handling. By default the app closes. --- tns-core-modules/ui/core/view/view-common.ts | 2 +- tns-core-modules/ui/core/view/view.android.ts | 2 +- tns-core-modules/ui/core/view/view.d.ts | 5 +++-- tns-core-modules/ui/frame/frame.android.ts | 4 ++-- tns-core-modules/ui/tab-view/tab-view.android.ts | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tns-core-modules/ui/core/view/view-common.ts b/tns-core-modules/ui/core/view/view-common.ts index 050dbeb75..c68e4b5d8 100644 --- a/tns-core-modules/ui/core/view/view-common.ts +++ b/tns-core-modules/ui/core/view/view-common.ts @@ -203,7 +203,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { return false; } - public _onBackPressed(): boolean { + public onBackPressed(): boolean { return false; } diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 646730d98..9a49221aa 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -115,7 +115,7 @@ function initializeDialogFragment() { }; view.notify(args); - if (!args.cancel && !view._onBackPressed()) { + if (!args.cancel && !view.onBackPressed()) { super.onBackPressed(); } } diff --git a/tns-core-modules/ui/core/view/view.d.ts b/tns-core-modules/ui/core/view/view.d.ts index f5af2eb0a..7e14dfb31 100644 --- a/tns-core-modules/ui/core/view/view.d.ts +++ b/tns-core-modules/ui/core/view/view.d.ts @@ -678,10 +678,11 @@ export abstract class View extends ViewBase { * @private */ _onLivesync(): boolean; + /** - * @private + * Derived classes can override this method to handle Android back button press. */ - _onBackPressed(): boolean; + onBackPressed(): boolean; /** * @private */ diff --git a/tns-core-modules/ui/frame/frame.android.ts b/tns-core-modules/ui/frame/frame.android.ts index 307fe8a40..1e42dfc2a 100644 --- a/tns-core-modules/ui/frame/frame.android.ts +++ b/tns-core-modules/ui/frame/frame.android.ts @@ -249,7 +249,7 @@ export class Frame extends FrameBase { } } - public _onBackPressed(): boolean { + public onBackPressed(): boolean { if (this.canGoBack()) { this.goBack(); return true; @@ -884,7 +884,7 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks { }; view.notify(viewArgs); - if (!viewArgs.cancel && !view._onBackPressed()) { + if (!viewArgs.cancel && !view.onBackPressed()) { callSuper = true; } } diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index c4ea595e1..a07315e35 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -510,10 +510,10 @@ export class TabView extends TabViewBase { super.disposeNativeView(); } - public _onBackPressed(): boolean { + public onBackPressed(): boolean { const currentView = this._selectedView; if (currentView) { - return currentView._onBackPressed(); + return currentView.onBackPressed(); } return false;