1
1
import { themer } from '@nativescript-community/ui-material-core' ;
2
2
import { Application , Color , Screen , Utils , backgroundColorProperty } from '@nativescript/core' ;
3
- import { BottomNavigationBarBase , BottomNavigationTabBase , activeColorCssProperty , inactiveColorCssProperty , tabsProperty , titleVisibilityProperty } from './bottomnavigationbar-common' ;
3
+ import { BottomNavigationBarBase , BottomNavigationTabBase , TitleVisibility , activeColorCssProperty , badgeColorCssProperty , badgeTextColorCssProperty , inactiveColorCssProperty , tabsProperty , titleVisibilityProperty } from './bottomnavigationbar-common' ;
4
4
5
5
@NativeClass
6
6
class BottomNavigationBarDelegate extends NSObject {
@@ -36,8 +36,6 @@ class BottomNavigationBarDelegate extends NSObject {
36
36
return bottomNavigationTab . isSelectable ;
37
37
}
38
38
}
39
- {
40
- }
41
39
export class BottomNavigationBar extends BottomNavigationBarBase {
42
40
nativeViewProtected : MDCBottomNavigationBar ;
43
41
_items : BottomNavigationTab [ ] ;
@@ -107,13 +105,20 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
107
105
this . createTabs ( tabs ) ;
108
106
}
109
107
110
- [ titleVisibilityProperty . setNative ] ( titleVisibility : MDCBottomNavigationBarTitleVisibility ) {
111
- this . nativeViewProtected . titleVisibility = titleVisibility ;
108
+ [ titleVisibilityProperty . setNative ] ( titleVisibility : TitleVisibility ) {
109
+ this . nativeViewProtected . titleVisibility = titleVisibility as number ;
112
110
}
113
111
114
112
[ activeColorCssProperty . setNative ] ( activeColor : Color ) {
115
113
this . nativeViewProtected . selectedItemTintColor = activeColor ? activeColor . ios : null ;
116
114
}
115
+ [ badgeColorCssProperty . setNative ] ( color : Color ) {
116
+ this . nativeViewProtected . itemBadgeBackgroundColor = color ? color . ios : null ;
117
+ }
118
+
119
+ [ badgeTextColorCssProperty . setNative ] ( color : Color ) {
120
+ this . nativeViewProtected . itemBadgeTextColor = color ? color . ios : null ;
121
+ }
117
122
118
123
[ inactiveColorCssProperty . setNative ] ( inactiveColor : Color ) {
119
124
this . nativeViewProtected . unselectedItemTintColor = inactiveColor ? inactiveColor . ios : null ;
@@ -136,45 +141,61 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
136
141
} ) ;
137
142
this . nativeViewProtected . items = new NSArray ( { array : bottomNavigationTabs } ) ;
138
143
139
- this . selectTabNative ( this . selectedTabIndex ) ;
144
+ this . nativeViewProtected . selectedItem = this . nativeViewProtected . items [ this . selectedTabIndex ] ;
140
145
}
141
146
142
147
protected selectTabNative ( index : number ) : void {
143
148
if ( this . nativeViewProtected . items . count === 0 ) {
144
149
return ;
145
150
}
146
-
147
- this . nativeViewProtected . selectedItem = this . nativeViewProtected . items [ index ] ;
148
- this . selectedTabIndex = index ;
151
+ // ios impl does not trigger delegates!
152
+ const itemToSelect = this . nativeViewProtected . items [ index ] ;
153
+ if ( this . _delegate . bottomNavigationBarShouldSelectItem ( this . nativeViewProtected , itemToSelect ) ) {
154
+ this . nativeViewProtected . selectedItem = this . nativeViewProtected . items [ index ] ;
155
+ this . _delegate . bottomNavigationBarDidSelectItem ( this . nativeViewProtected , itemToSelect ) ;
156
+ this . selectedTabIndex = index ;
157
+ }
149
158
}
150
159
}
151
160
152
161
// Bottom Navigation Tab
153
162
163
+ declare class MDCBottomNavigationItemView extends UIView {
164
+ selectedItemTintColor : UIColor ;
165
+ unselectedItemTintColor : UIColor ;
166
+ selectedItemTitleColor : UIColor ;
167
+ badgeTextColor : UIColor ;
168
+ badgeColor : UIColor ;
169
+ }
170
+
154
171
export class BottomNavigationTab extends BottomNavigationTabBase {
155
172
nativeViewProtected : UITabBarItem ;
156
173
createNativeView ( ) {
157
- return UITabBarItem . alloc ( ) . initWithTitleImageTag ( this . title , this . getNativeIcon ( ) , 0 ) ;
174
+ let icon = this . getNativeIcon ( ) ;
175
+ if ( icon ) {
176
+ icon = icon . imageWithRenderingMode ( UIImageRenderingMode . Automatic ) ;
177
+ }
178
+ return UITabBarItem . alloc ( ) . initWithTitleImageTag ( this . title , icon , 0 ) ;
158
179
}
159
180
160
181
getNativeIcon ( ) : UIImage {
161
182
return this . icon && this . icon . ios ;
162
183
}
163
184
164
185
getMDView ( ) {
165
- return ( this . parent as BottomNavigationBar ) . nativeViewProtected . viewForItem ( this . nativeViewProtected ) as any ;
186
+ return ( this . parent as BottomNavigationBar ) . nativeViewProtected . viewForItem ( this . nativeViewProtected ) as MDCBottomNavigationItemView ;
166
187
}
167
188
168
189
[ activeColorCssProperty . setNative ] ( activeColor : Color ) {
169
- // not working for now
170
- // const color = activeColor ? activeColor.ios : null;
171
- // this.getMDView().selectedItemTintColor = color;
190
+ const color = activeColor ? activeColor . ios : null ;
191
+ // TODO: it wont work for now as MDCBottomNavigationItemView is not exposed
192
+ this . getMDView ( ) . selectedItemTintColor = color ;
172
193
}
173
194
174
195
[ inactiveColorCssProperty . setNative ] ( inactiveColor : Color ) {
175
- // not working for now
176
- // const color = inactiveColor ? inactiveColor.ios : null;
177
- // this.getMDView().unselectedItemTintColor = color;
196
+ const color = inactiveColor ? inactiveColor . ios : null ;
197
+ // TODO: it wont work for now as MDCBottomNavigationItemView is not exposed
198
+ this . getMDView ( ) . unselectedItemTintColor = color ;
178
199
}
179
200
180
201
showBadge ( value ?: number ) : void {
0 commit comments