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