mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
Resolve "Very unusual back button behavior"
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
import {Directive, HostListener, Input, Optional} from '@angular/core';
|
||||
import {
|
||||
AnimationBuilder,
|
||||
Config,
|
||||
IonBackButtonDelegate,
|
||||
IonRouterOutlet,
|
||||
NavController,
|
||||
} from '@ionic/angular';
|
||||
|
||||
/**
|
||||
* Overrides the default ion-back-button directive.
|
||||
*
|
||||
* @see https://github.com/ionic-team/ionic-framework/blob/main/angular/src/directives/navigation/ion-back-button.ts
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'ion-back-button',
|
||||
})
|
||||
export class IonBackButtonOverrideDirective {
|
||||
@Input()
|
||||
defaultHref: string | undefined | null;
|
||||
|
||||
@Input()
|
||||
routerAnimation?: AnimationBuilder;
|
||||
|
||||
constructor(
|
||||
@Optional() private routerOutlet: IonRouterOutlet,
|
||||
private navCtrl: NavController,
|
||||
private config: Config,
|
||||
private ionBackButton: IonBackButtonDelegate,
|
||||
) {
|
||||
this.ionBackButton.onClick = () => {
|
||||
// Override default onClick to prevent double execution and errors
|
||||
};
|
||||
}
|
||||
|
||||
@HostListener('click', ['$event'])
|
||||
onClick(event: Event): void {
|
||||
const defaultHref =
|
||||
this.defaultHref || this.config.get('backButtonDefaultHref');
|
||||
|
||||
// Handle back via angular navCtrl.back()
|
||||
// (which is animated, instead of location.back)
|
||||
if (defaultHref === '..') {
|
||||
this.navCtrl.back();
|
||||
} else if (this.routerOutlet?.canGoBack()) {
|
||||
this.navCtrl.setDirection(
|
||||
'back',
|
||||
undefined,
|
||||
undefined,
|
||||
this.routerAnimation,
|
||||
);
|
||||
this.routerOutlet.pop();
|
||||
event.preventDefault();
|
||||
} else if (defaultHref != undefined) {
|
||||
this.navCtrl.navigateBack(defaultHref, {animation: this.routerAnimation});
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import {DateFromIndexPipe} from './date-from-index.pipe';
|
||||
import {DaytimeKeyPipe} from './daytime-key.pipe';
|
||||
import {LazyPipe} from './lazy.pipe';
|
||||
import {NextDateInListPipe} from './next-date-in-list.pipe';
|
||||
import {IonBackButtonOverrideDirective} from './ion-back-button.directive';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -32,7 +31,6 @@ import {IonBackButtonOverrideDirective} from './ion-back-button.directive';
|
||||
DateFromIndexPipe,
|
||||
DaytimeKeyPipe,
|
||||
NextDateInListPipe,
|
||||
IonBackButtonOverrideDirective,
|
||||
],
|
||||
exports: [
|
||||
ArrayLastPipe,
|
||||
@@ -42,7 +40,6 @@ import {IonBackButtonOverrideDirective} from './ion-back-button.directive';
|
||||
DateFromIndexPipe,
|
||||
DaytimeKeyPipe,
|
||||
NextDateInListPipe,
|
||||
IonBackButtonOverrideDirective,
|
||||
],
|
||||
})
|
||||
export class UtilModule {}
|
||||
|
||||
Reference in New Issue
Block a user