mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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.
This commit is contained in:
@@ -203,7 +203,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
return false;
|
||||
}
|
||||
|
||||
public _onBackPressed(): boolean {
|
||||
public onBackPressed(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ function initializeDialogFragment() {
|
||||
};
|
||||
view.notify(args);
|
||||
|
||||
if (!args.cancel && !view._onBackPressed()) {
|
||||
if (!args.cancel && !view.onBackPressed()) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
5
tns-core-modules/ui/core/view/view.d.ts
vendored
5
tns-core-modules/ui/core/view/view.d.ts
vendored
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user