fix touch menu toggle
This commit is contained in:
parent
86d352f549
commit
fda829745e
@ -34,8 +34,7 @@
|
||||
</mat-toolbar>
|
||||
|
||||
<mat-sidenav-container>
|
||||
<mat-sidenav #sidenav [mode]="isBiggerScreen() ? 'side' : 'over'" [(opened)]="opened"
|
||||
(click)="!isBiggerScreen() && opened=false">
|
||||
<mat-sidenav #sidenav [mode]="isBiggerScreen() ? 'side' : 'over'">
|
||||
<mat-nav-list>
|
||||
<a *ngIf="!auth || auth && !auth.authenticated" routerLink="/login" routerLinkActive="active" mat-list-item>
|
||||
<mat-icon>login</mat-icon> {{'login' | i18n}}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {Component, HostListener} from '@angular/core';
|
||||
import { Component, HostListener, ViewChild } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { MatIconRegistry } from '@angular/material/icon';
|
||||
@ -8,6 +8,7 @@ import { fromEvent } from 'rxjs';
|
||||
import { AuthService } from '../../services/auth.service';
|
||||
import { I18nService } from '../../services/i18n.service';
|
||||
import { ProfileService } from '../../services/profile.service';
|
||||
import { MatSidenav } from '@angular/material/sidenav';
|
||||
|
||||
@Component({
|
||||
selector: 'app-main',
|
||||
@ -15,7 +16,9 @@ import {ProfileService} from '../../services/profile.service';
|
||||
styleUrls: [ './main.component.scss' ]
|
||||
})
|
||||
export class MainComponent {
|
||||
opened = true;
|
||||
|
||||
@ViewChild(MatSidenav) sidenav: MatSidenav;
|
||||
|
||||
darkTheme = "false";
|
||||
title = 'we.bstly';
|
||||
currentLocale: String;
|
||||
@ -50,9 +53,9 @@ export class MainComponent {
|
||||
|
||||
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
||||
if (width < 768) {
|
||||
this.opened = false;
|
||||
this.sidenav?.close();
|
||||
} else {
|
||||
this.opened = true;
|
||||
this.sidenav?.open();
|
||||
}
|
||||
|
||||
if (localStorage.getItem("bstly.darkTheme") == "true") {
|
||||
@ -142,9 +145,9 @@ export class MainComponent {
|
||||
@HostListener('window:resize', [ '$event' ])
|
||||
onResize(event) {
|
||||
if (event.target.innerWidth < 768) {
|
||||
this.opened = false;
|
||||
this.sidenav?.close();
|
||||
} else {
|
||||
this.opened = true;
|
||||
this.sidenav?.open();
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,12 +166,15 @@ export class MainComponent {
|
||||
})
|
||||
|
||||
fromEvent(document, 'touchend').subscribe((event: TouchEvent) => {
|
||||
if (this.touchX != 0) {
|
||||
const touchDiff = this.touchStartX - this.touchX;
|
||||
|
||||
if (touchDiff < 0 && touchDiff < (this.touchThresh * -1) && !this.opened) {
|
||||
this.opened = true;
|
||||
} else if (touchDiff > 0 && touchDiff > this.touchThresh && this.opened) {
|
||||
this.opened = false;
|
||||
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();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user