import { AfterViewInit , Directive } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { Page } from '@nativescript/core' ; import { themer } from '@nativescript-community/ui-material-core' ; @ Directive ( { selector : '[materialAppBar]' } ) export class AppBarDirective implements AfterViewInit { _appBarController : MDCAppBarViewController ; addedToParent = false ; constructor ( route , private page ) { this . createNativeView ( ) ; } public createNativeView ( ) { this . _appBarController = MDCAppBarViewController . alloc ( ) . init ( ) ; const colorScheme = themer . getAppColorScheme ( ) as MDCSemanticColorScheme ; if ( colorScheme ) { MDCAppBarColorThemer . applyColorSchemeToAppBarViewController ( colorScheme , this . _appBarController ) ; } this . _addController ( ) ; return null ; } private _addController ( ) { if ( this . _appBarController && ! this . addedToParent ) { const page = this . page ; if ( page && page . parent ) { page [ 'customNavigationBar' ] = true ; const viewController = page . ios as UIViewController ; if ( viewController . navigationController ) { viewController . navigationController . navigationBarHidden = true ; } this . addedToParent = true ; } } } ngAfterViewInit ( ) { this . _addController ( ) ; const viewController = this . page . ios as UIViewController ; if ( viewController . navigationController ) { viewController . navigationController . setNavigationBarHiddenAnimated ( true , false ) ; } viewController . view . addSubview ( this . _appBarController . view ) ; this . _appBarController . didMoveToParentViewController ( viewController ) ; } }