@nativescript/template-drawer-navigation-ng
Version:
Side navigation template
52 lines (43 loc) • 1.46 kB
text/typescript
import { Component, OnInit } from '@angular/core'
import { NavigationEnd, Router } from '@angular/router'
import { RouterExtensions } from '@nativescript/angular'
import {
DrawerTransitionBase,
RadSideDrawer,
SlideInOnTopTransition,
} from 'nativescript-ui-sidedrawer'
import { filter } from 'rxjs/operators'
import { Application } from '@nativescript/core'
({
selector: 'ns-app',
templateUrl: 'app.component.html',
})
export class AppComponent implements OnInit {
private _activatedUrl: string
private _sideDrawerTransition: DrawerTransitionBase
constructor(private router: Router, private routerExtensions: RouterExtensions) {
// Use the component constructor to inject services.
}
ngOnInit(): void {
this._activatedUrl = '/home'
this._sideDrawerTransition = new SlideInOnTopTransition()
this.router.events
.pipe(filter((event: any) => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => (this._activatedUrl = event.urlAfterRedirects))
}
get sideDrawerTransition(): DrawerTransitionBase {
return this._sideDrawerTransition
}
isComponentSelected(url: string): boolean {
return this._activatedUrl === url
}
onNavItemTap(navItemRoute: string): void {
this.routerExtensions.navigate([navItemRoute], {
transition: {
name: 'fade',
},
})
const sideDrawer = <RadSideDrawer>Application.getRootView()
sideDrawer.closeDrawer()
}
}