fix touch menu toggle

This commit is contained in:
_Bastler 2021-11-21 16:37:37 +01:00
parent fda829745e
commit 01f399e547
2 changed files with 11 additions and 11 deletions

View File

@ -34,7 +34,8 @@
</mat-toolbar>
<mat-sidenav-container>
<mat-sidenav #sidenav [mode]="isBiggerScreen() ? 'side' : 'over'">
<mat-sidenav #sidenav [mode]="isBiggerScreen() ? 'side' : 'over'" [(opened)]="opened"
(click)="!isBiggerScreen() && opened=false">
<mat-nav-list>
<a *ngIf="!auth || auth && !auth.authenticated" routerLink="/login" routerLinkActive="active" mat-list-item>
<mat-icon>login</mat-icon> {{'login' | i18n}}

View File

@ -17,8 +17,7 @@ import { MatSidenav } from '@angular/material/sidenav';
})
export class MainComponent {
@ViewChild(MatSidenav) sidenav: MatSidenav;
opened : boolean = true;
darkTheme = "false";
title = 'we.bstly';
currentLocale: String;
@ -53,9 +52,9 @@ export class MainComponent {
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if (width < 768) {
this.sidenav?.close();
this.opened = false;
} else {
this.sidenav?.open();
this.opened = true;
}
if (localStorage.getItem("bstly.darkTheme") == "true") {
@ -145,9 +144,9 @@ export class MainComponent {
@HostListener('window:resize', [ '$event' ])
onResize(event) {
if (event.target.innerWidth < 768) {
this.sidenav?.close();
this.opened = false;
} else {
this.sidenav?.open();
this.opened = true;
}
}
@ -170,10 +169,10 @@ export class MainComponent {
const touchDiff = this.touchStartX - this.touchX;
this.touchStartX = 0;
this.touchX = 0;
if (touchDiff < 0 && touchDiff < (this.touchThresh * -1) && !this.sidenav.opened) {
this.sidenav.open();
} else if (touchDiff > 0 && touchDiff > this.touchThresh && this.sidenav.opened) {
this.sidenav.close();
if (touchDiff < 0 && touchDiff < (this.touchThresh * -1) && !this.opened) {
this.opened = true;
} else if (touchDiff > 0 && touchDiff > this.touchThresh && this.opened) {
this.opened = false;
}
}
})