1
1
import { Directive , Component , ElementRef , Optional , OnDestroy } from "@angular/core" ;
2
- import { ActionItem , ActionBar , NavigationButton } from "tns-core-modules/ui/action-bar" ;
2
+ import {
3
+ ActionBar ,
4
+ ActionItem ,
5
+ ActionItems ,
6
+ NavigationButton ,
7
+ } from "tns-core-modules/ui/action-bar" ;
3
8
import { Page } from "tns-core-modules/ui/page" ;
4
9
import { View } from "tns-core-modules/ui/core/view" ;
5
10
@@ -25,14 +30,14 @@ type NgActionBar = (ActionBar & ViewExtensions);
25
30
26
31
const actionBarMeta : ViewClassMeta = {
27
32
skipAddToDom : true ,
28
- insertChild : ( parent : NgActionBar , child : NgView , previous : NgView ) => {
33
+ insertChild : ( parent : NgActionBar , child : NgView , next : any ) => {
29
34
if ( isInvisibleNode ( child ) ) {
30
35
return ;
31
36
} else if ( isNavigationButton ( child ) ) {
32
37
parent . navigationButton = child ;
33
38
child . templateParent = parent ;
34
39
} else if ( isActionItem ( child ) ) {
35
- parent . actionItems . addItem ( child ) ;
40
+ addActionItem ( parent , child , next ) ;
36
41
child . templateParent = parent ;
37
42
} else if ( isView ( child ) ) {
38
43
parent . titleView = child ;
@@ -56,6 +61,28 @@ const actionBarMeta: ViewClassMeta = {
56
61
} ,
57
62
} ;
58
63
64
+ const addActionItem = ( bar : NgActionBar , item : ActionItem , next : ActionItem ) => {
65
+ if ( next ) {
66
+ insertActionItemBefore ( bar , item , next ) ;
67
+ } else {
68
+ appendActionItem ( bar , item ) ;
69
+ }
70
+ } ;
71
+
72
+ const insertActionItemBefore = ( bar : NgActionBar , item : ActionItem , next : ActionItem ) => {
73
+ const actionItems : ActionItems = bar . actionItems ;
74
+ const actionItemsCollection : ActionItem [ ] = actionItems . getItems ( ) ;
75
+
76
+ const indexToInsert = actionItemsCollection . indexOf ( next ) ;
77
+ actionItemsCollection . splice ( indexToInsert , 0 , item ) ;
78
+
79
+ ( < any > actionItems ) . setItems ( actionItemsCollection ) ;
80
+ } ;
81
+
82
+ const appendActionItem = ( bar : NgActionBar , item : ActionItem ) => {
83
+ bar . actionItems . addItem ( item ) ;
84
+ } ;
85
+
59
86
registerElement ( "ActionBar" , ( ) => require ( "ui/action-bar" ) . ActionBar , actionBarMeta ) ;
60
87
registerElement ( "ActionItem" , ( ) => require ( "ui/action-bar" ) . ActionItem ) ;
61
88
registerElement ( "NavigationButton" , ( ) => require ( "ui/action-bar" ) . NavigationButton ) ;
0 commit comments