import { Component } from '@angular/core' ; import { ActionBarComponent , NgView , ViewClassMeta , ViewExtensions , isInvisibleNode , isView } from '@nativescript/angular' ; import { ActionBar , ActionItem , ActionItems , NavigationButton } from '@nativescript/core' ; export function isActionItem ( view ) { return view instanceof ActionItem ; } export function isNavigationButton ( view ) { return view instanceof NavigationButton ; } type NgActionBar = ActionBar & ViewExtensions ; export const appBarMeta = { skipAddToDom : true , insertChild : ( parent , child , next ) => { if ( isInvisibleNode ( child ) ) { return ; } else if ( isNavigationButton ( child ) ) { parent . navigationButton = child ; child . parentNode = parent ; } else if ( isActionItem ( child ) ) { addActionItem ( parent , child , next ) ; child . parentNode = parent ; } else if ( isView ( child ) ) { parent . titleView = child ; } } , removeChild : ( parent , child ) => { if ( isInvisibleNode ( child ) ) { return ; } else if ( isNavigationButton ( child ) ) { if ( parent . navigationButton === child ) { parent . navigationButton = null ; } child . parentNode = null ; } else if ( isActionItem ( child ) ) { parent . actionItems . removeItem ( child ) ; child . parentNode = null ; } else if ( isView ( child ) && parent . titleView && parent . titleView === child ) { parent . titleView = null ; } } } ; const addActionItem = ( bar , item , next ) => { if ( next ) { insertActionItemBefore ( bar , item , next ) ; } else { appendActionItem ( bar , item ) ; } } ; const insertActionItemBefore = ( bar , item , next ) => { const actionItems = bar . actionItems ; const actionItemsCollection = actionItems . getItems ( ) ; const indexToInsert = actionItemsCollection . indexOf ( next ) ; actionItemsCollection . splice ( indexToInsert , 0 , item ) ; ( actionItems as any ) . setItems ( actionItemsCollection ) ; } ; const appendActionItem = ( bar , item ) => { bar . actionItems . addItem ( item ) ; } ; @ Component ( { selector : 'AppBar' , template : '<ng-content></ng-content>' } ) export class AppBarComponent extends ActionBarComponent { }