diff --git a/src/common/config/public/ClientConfig.ts b/src/common/config/public/ClientConfig.ts index 354380ca..2381aec6 100644 --- a/src/common/config/public/ClientConfig.ts +++ b/src/common/config/public/ClientConfig.ts @@ -429,6 +429,15 @@ export class NavBarConfig { new NavigationLinkConfig(NavigationLinkTypes.albums), new NavigationLinkConfig(NavigationLinkTypes.faces), ]; + @ConfigProperty({ + tags: { + name: $localize`Navbar show/hide delay`, + priority: ConfigPriority.underTheHood + }, + type: 'ratio', + description: $localize`Ratio of the page height, you need to scroll to show or hide the navigationbar.`, + }) + NavbarShowHideDelay: number = 0.15; } @SubConfigClass({tags: {client: true}, softReadonly: true}) diff --git a/src/frontend/app/ui/frame/frame.component.ts b/src/frontend/app/ui/frame/frame.component.ts index e46e10e5..b2e8274e 100644 --- a/src/frontend/app/ui/frame/frame.component.ts +++ b/src/frontend/app/ui/frame/frame.component.ts @@ -32,10 +32,14 @@ export class FrameComponent { public readonly stringify = JSON.stringify; /* sticky top navbar */ - private lastScroll = 0; + private lastScroll = { + any: 0, + up: 0, + down: 0 + }; public shouldHideNavbar = false; public navbarKeepTop = true; - public animateNavbar = false; + public animateNavbar = false; @ViewChild('navContainer', {static: true}) navContainer: ElementRef; @ViewChild('dropdown', {static: true}) dropdown: BsDropdownDirective; @ViewChild('languageSelector', {static: true}) languageSelector: LanguageComponent; @@ -88,35 +92,48 @@ export class FrameComponent { } - @HostListener('window:scroll') onScroll(): void { - const up = this.lastScroll > PageHelper.ScrollY; - const down = this.lastScroll < PageHelper.ScrollY; + const scrollPosition = PageHelper.ScrollY; + const up = this.lastScroll.any > scrollPosition; + const down = this.lastScroll.any < scrollPosition; + const upDelay = up && this.lastScroll.down > scrollPosition + window.innerHeight * Config.Gallery.NavBar.NavbarShowHideDelay; + const downDelay = down && this.lastScroll.up < scrollPosition - window.innerHeight * Config.Gallery.NavBar.NavbarShowHideDelay; + //we are the top where the navbar by default lives - if (this.navContainer.nativeElement.offsetHeight > PageHelper.ScrollY) { + if (this.navContainer.nativeElement.offsetHeight > scrollPosition) { // do not force move navbar up when we are scrolling up from bottom if (this.shouldHideNavbar != false) { this.navbarKeepTop = true; } + if (down) { // scroll down + this.shouldHideNavbar = true; + } } else { // enable navigation once we left the top part to prevent hide extra animation this.animateNavbar = !(this.navbarKeepTop && down); this.navbarKeepTop = false; - if (down) { + + if (downDelay) { // scroll down this.dropdown.hide(); this.languageSelector.dropdown.hide(); } } - if (up) { //scroll up + if (upDelay) { //scroll up this.shouldHideNavbar = false; - } else if (down) { // scroll down + } else if (downDelay) { // scroll down this.shouldHideNavbar = true; } - this.lastScroll = PageHelper.ScrollY; + if (up) { //scroll up + this.lastScroll.up = scrollPosition; + } else if (down) { // scroll down + this.lastScroll.down = scrollPosition; + } + + this.lastScroll.any = scrollPosition; } } diff --git a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts index a75d7f7f..29def038 100644 --- a/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts +++ b/src/frontend/app/ui/gallery/navigator/navigator.gallery.component.ts @@ -34,9 +34,13 @@ export class GalleryNavigatorComponent { private readonly RootFolderName: string; private parentPath: string = null; - private lastScroll = 0; + private lastScroll = { + any: 0, + up: 0, + down: 0 + }; @ViewChild('dropdown', {static: true}) dropdown: BsDropdownDirective; - @ViewChild('navigator', { read: ElementRef }) navigatorElement: ElementRef; + @ViewChild('navigator', {read: ElementRef}) navigatorElement: ElementRef; constructor( public authService: AuthenticationService, @@ -192,11 +196,18 @@ export class GalleryNavigatorComponent { @HostListener('window:scroll') onScroll(): void { - if (this.lastScroll < PageHelper.ScrollY) { // scroll down - this.showFilters = false; - this.dropdown.hide(); + const scrollPosition = PageHelper.ScrollY; + if (this.lastScroll.any < scrollPosition) { // scroll down + //hide delay + if (this.lastScroll.up < scrollPosition - window.innerHeight * Config.Gallery.NavBar.NavbarShowHideDelay) { + this.showFilters = false; + this.dropdown.hide(); + } + this.lastScroll.down = scrollPosition; + } else if (this.lastScroll.any > scrollPosition) { + this.lastScroll.up = scrollPosition; } - this.lastScroll = PageHelper.ScrollY; + this.lastScroll.any = scrollPosition; } }