import { themer } from '@nativescript-community/ui-material-core' ; import { Utils } from '@nativescript/core' ; import { AppBarBase } from './appbar-common' ; export class AppBar extends AppBarBase { _appBarController : MDCAppBarViewController ; addedToParent = false ; public createNativeView ( ) { this . _appBarController = MDCAppBarViewController . alloc ( ) . init ( ) ; const colorScheme = themer . getAppColorScheme ( ) as MDCSemanticColorScheme ; if ( colorScheme ) { MDCAppBarColorThemer . applyColorSchemeToAppBarViewController ( colorScheme , this . _appBarController ) ; } this . _addController ( ) ; return null ; } get nativeViewProtected ( ) { return this . _appBarController ? this . _appBarController . navigationBar : null ; } set nativeViewProtected ( view ) { } public get _getActualSize ( ) : { width : number ; height : number ; } { const navBar = this . ios ; if ( ! navBar ) { return { width : 0 , height : 0 } ; } const size = navBar . sizeThatFits ( this . _appBarController . navigationBar . frame . size ) ; const width = Utils . layout . toDevicePixels ( size . width ) ; const height = Utils . layout . toDevicePixels ( size . height ) ; return { width , height } ; } private _addController ( ) { if ( this . _appBarController && ! this . addedToParent ) { const page = this . page ; if ( page && page . parent ) { let showNavigationBar = true ; Object . defineProperty ( page . frame . ios , 'showNavigationBar' , { get ( ) { return showNavigationBar ; } , set ( value ) { showNavigationBar = value ; } } ) ; const viewController = page . ios as UIViewController ; if ( viewController . navigationController ) { viewController . navigationController . navigationBarHidden = true ; } this . _appBarController . topLayoutGuideViewController = viewController ; this . _appBarController . inferPreferredStatusBarStyle = true ; this . _appBarController . inferTopSafeAreaInsetFromViewController = true ; this . _appBarController . topLayoutGuideAdjustmentEnabled = true ; viewController . addChildViewController ( this . _appBarController ) ; this . addedToParent = true ; } } } public onLoaded ( ) { super . onLoaded ( ) ; this . _addController ( ) ; const viewController = this . page . ios as UIViewController ; viewController . view . addSubview ( this . _appBarController . view ) ; this . _appBarController . didMoveToParentViewController ( viewController ) ; } }