-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrollingHeader.directive.ts
54 lines (46 loc) · 2 KB
/
scrollingHeader.directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Directive, ElementRef, Input, OnChanges, OnDestroy, Renderer2 } from '@angular/core';
import { Keyboard } from '@ionic-native/keyboard/ngx';
import { DomController } from '@ionic/angular';
import { TabBarHideShow } from '../../core/services/tab-bar-hide-show';
import { ScrollHideConfig } from '../../core/models/interfaces';
import { appConstants } from '../../core/constants';
@Directive({
selector: '[appScrollHide]'
})
export class ScrollHideDirective implements OnChanges, OnDestroy {
@Input('appScrollHide') scrollContent: any;
private config: ScrollHideConfig = appConstants.scrollConfigs;
constructor(
public tabBarService: TabBarHideShow,
private domCtrl: DomController,
private element: ElementRef,
private renderer: Renderer2,
private keyboard: Keyboard
) {}
ngOnChanges() {
if (this.scrollContent && this.config) {
this.scrollContent.ionScroll.subscribe(ev => {
if (ev) {
if (ev.detail.deltaY === 0) {
return;
}
if (ev.detail.scrollTop <= 0) {
this.renderer.setStyle(this.element.nativeElement, 'visibility', `visible`);
this.tabBarService.isVisibleTabBar$.next(true);
return;
}
if (ev.detail.deltaY < 0) {
this.renderer.setStyle(this.element.nativeElement, 'visibility', `visible`);
this.tabBarService.isVisibleTabBar$.next(false);
} else if (ev.detail.scrollTop >= ev.currentTarget.offsetTop && !this.keyboard.isVisible) {
this.renderer.setStyle(this.element.nativeElement, 'visibility', `hidden`);
this.tabBarService.isVisibleTabBar$.next(true);
}
}
});
}
}
ngOnDestroy() {
this.tabBarService.isVisibleTabBar$.next(true);
}
}