@@ -71,20 +71,19 @@ class UITabBarControllerImpl extends UITabBarController {
71
71
72
72
public viewWillTransitionToSizeWithTransitionCoordinator ( size : CGSize , coordinator : UIViewControllerTransitionCoordinator ) : void {
73
73
super . viewWillTransitionToSizeWithTransitionCoordinator ( size , coordinator ) ;
74
- UIViewControllerTransitionCoordinator . prototype . animateAlongsideTransitionCompletion
75
- . call ( coordinator , ( ) => {
76
- const owner = this . _owner . get ( ) ;
77
- if ( owner && owner . tabStrip && owner . tabStrip . items ) {
78
- const tabStrip = owner . tabStrip ;
79
- tabStrip . items . forEach ( tabStripItem => {
80
- updateBackgroundPositions ( tabStrip , tabStripItem ) ;
81
-
82
- const index = tabStripItem . _index ;
83
- const tabBarItemController = this . viewControllers [ index ] ;
84
- updateTitleAndIconPositions ( tabStripItem , tabBarItemController . tabBarItem , tabBarItemController ) ;
85
- } ) ;
86
- }
87
- } , null ) ;
74
+ coordinator . animateAlongsideTransitionCompletion ( ( ) => {
75
+ const owner = this . _owner . get ( ) ;
76
+ if ( owner && owner . tabStrip && owner . tabStrip . items ) {
77
+ const tabStrip = owner . tabStrip ;
78
+ tabStrip . items . forEach ( tabStripItem => {
79
+ updateBackgroundPositions ( tabStrip , tabStripItem ) ;
80
+
81
+ const index = tabStripItem . _index ;
82
+ const tabBarItemController = this . viewControllers [ index ] ;
83
+ updateTitleAndIconPositions ( tabStripItem , tabBarItemController . tabBarItem , tabBarItemController ) ;
84
+ } ) ;
85
+ }
86
+ } , null ) ;
88
87
}
89
88
90
89
// Mind implementation for other controllers
@@ -207,17 +206,14 @@ class UINavigationControllerDelegateImpl extends NSObject implements UINavigatio
207
206
208
207
function updateBackgroundPositions ( tabStrip : TabStrip , tabStripItem : TabStripItem ) {
209
208
let bgView = ( < any > tabStripItem ) . bgView ;
209
+ const index = tabStripItem . _index ;
210
+ const width = tabStrip . nativeView . frame . size . width / tabStrip . items . length ;
211
+ const frame = CGRectMake ( width * index , 0 , width , tabStrip . nativeView . frame . size . width ) ;
210
212
if ( ! bgView ) {
211
- const index = tabStripItem . _index ;
212
- const width = tabStrip . nativeView . frame . size . width / tabStrip . items . length ;
213
- const frame = CGRectMake ( width * index , 0 , width , tabStrip . nativeView . frame . size . width ) ;
214
213
bgView = UIView . alloc ( ) . initWithFrame ( frame ) ;
215
214
tabStrip . nativeView . insertSubviewAtIndex ( bgView , 0 ) ;
216
215
( < any > tabStripItem ) . bgView = bgView ;
217
216
} else {
218
- const index = tabStripItem . _index ;
219
- const width = tabStrip . nativeView . frame . size . width / tabStrip . items . length ;
220
- const frame = CGRectMake ( width * index , 0 , width , tabStrip . nativeView . frame . size . width ) ;
221
217
bgView . frame = frame ;
222
218
}
223
219
@@ -376,8 +372,7 @@ export class BottomNavigation extends TabNavigationBase {
376
372
}
377
373
378
374
public setTabBarItemColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
379
- const states = getTitleAttributesForStates ( tabStripItem . label ) ;
380
- applyStatesToItem ( tabStripItem . nativeView , states , this . viewController . tabBar ) ;
375
+ setViewTextAttributes ( tabStripItem . nativeView , tabStripItem . label , this . viewController . tabBar ) ;
381
376
}
382
377
383
378
public setTabBarIconColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
@@ -388,15 +383,23 @@ export class BottomNavigation extends TabNavigationBase {
388
383
}
389
384
390
385
public setTabBarItemFontInternal ( tabStripItem : TabStripItem , value : Font ) : void {
391
- const states = getTitleAttributesForStates ( tabStripItem . label ) ;
392
- applyStatesToItem ( tabStripItem . nativeView , states , this . viewController . tabBar ) ;
386
+ setViewTextAttributes ( tabStripItem . nativeView , tabStripItem . label , this . viewController . tabBar ) ;
393
387
}
394
388
395
389
public setTabBarItemTextTransform ( tabStripItem : TabStripItem , value : TextTransform ) : void {
396
390
const title = getTransformedText ( tabStripItem . label . text , value ) ;
397
391
tabStripItem . nativeView . title = title ;
398
392
}
399
393
394
+ public getTabBarHighlightColor ( ) : UIColor {
395
+ return this . _ios . tabBar . tintColor ;
396
+ }
397
+
398
+ public setTabBarHighlightColor ( value : UIColor | Color ) {
399
+ const nativeColor = value instanceof Color ? value . ios : value ;
400
+ this . _ios . tabBar . tintColor = nativeColor ;
401
+ }
402
+
400
403
public onMeasure ( widthMeasureSpec : number , heightMeasureSpec : number ) : void {
401
404
const width = layout . getMeasureSpecSize ( widthMeasureSpec ) ;
402
405
const widthMode = layout . getMeasureSpecMode ( widthMeasureSpec ) ;
@@ -518,8 +521,7 @@ export class BottomNavigation extends TabNavigationBase {
518
521
const tabBarItem = this . createTabBarItem ( tabStripItem , i ) ;
519
522
updateTitleAndIconPositions ( tabStripItem , tabBarItem , controller ) ;
520
523
521
- const states = getTitleAttributesForStates ( tabStripItem . label ) ;
522
- applyStatesToItem ( tabBarItem , states , this . viewController . tabBar ) ;
524
+ setViewTextAttributes ( tabBarItem , tabStripItem . label , this . viewController . tabBar ) ;
523
525
524
526
controller . tabBarItem = tabBarItem ;
525
527
tabStripItem . _index = i ;
@@ -688,51 +690,31 @@ export class BottomNavigation extends TabNavigationBase {
688
690
}
689
691
}
690
692
691
- interface TabStates {
692
- normalState ?: any ;
693
- selectedState ?: any ;
694
- }
695
-
696
- function getTitleAttributesForStates ( view : View ) : TabStates {
693
+ function setViewTextAttributes ( item : UITabBarItem , view : View , tabBar : UITabBar ) : any {
697
694
if ( ! view ) {
698
695
return null ;
699
696
}
700
697
701
- const result : TabStates = { } ;
702
698
const defaultTabItemFontSize = 10 ;
703
699
const tabItemFontSize = view . style . fontSize || defaultTabItemFontSize ;
704
700
const font : UIFont = view . style . fontInternal . getUIFont ( UIFont . systemFontOfSize ( tabItemFontSize ) ) ;
705
701
const tabItemTextColor = view . style . color ;
706
702
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor . ios : null ;
707
- result . normalState = { [ NSFontAttributeName ] : font } ;
703
+ let attributes : any = { [ NSFontAttributeName ] : font } ;
708
704
if ( textColor ) {
709
- result . normalState [ UITextAttributeTextColor ] = textColor ;
705
+ attributes [ UITextAttributeTextColor ] = textColor ;
706
+ attributes [ NSForegroundColorAttributeName ] = textColor ;
710
707
}
711
708
712
- const tabSelectedItemTextColor = view . style . color ;
713
- const selectedTextColor = tabSelectedItemTextColor instanceof Color ? tabSelectedItemTextColor . ios : null ;
714
- result . selectedState = { [ NSFontAttributeName ] : font } ;
715
- if ( selectedTextColor ) {
716
- result . selectedState [ UITextAttributeTextColor ] = selectedTextColor ;
717
- }
718
-
719
- return result ;
720
- }
721
-
722
- function applyStatesToItem ( item : UITabBarItem , states : TabStates , tabBar : UITabBar ) {
723
- if ( ! states ) {
724
- return ;
725
- }
726
-
727
- item . setTitleTextAttributesForState ( states . normalState , UIControlState . Normal ) ;
728
- item . setTitleTextAttributesForState ( states . selectedState , UIControlState . Selected ) ;
709
+ item . setTitleTextAttributesForState ( attributes , UIControlState . Selected ) ;
710
+ item . setTitleTextAttributesForState ( attributes , UIControlState . Normal ) ;
729
711
730
712
// there's a bug when setting the item color on ios 13 if there's no background set to the tabstrip
731
713
// https://books.google.bg/books?id=99_BDwAAQBAJ&q=tabBar.unselectedItemTintColor
732
714
// to fix the above issue we are applying the selected fix only for the case, when there is no background set
733
715
// in that case we have the following known issue:
734
716
// we will set the color to all unselected items, so you won't be able to set different colors for the different not selected items
735
- if ( ! tabBar . barTintColor && states . normalState [ UITextAttributeTextColor ] && ( majorVersion > 9 ) ) {
736
- tabBar . unselectedItemTintColor = states . normalState [ UITextAttributeTextColor ] ;
717
+ if ( ! tabBar . barTintColor && attributes [ UITextAttributeTextColor ] && ( majorVersion > 9 ) ) {
718
+ tabBar . unselectedItemTintColor = attributes [ UITextAttributeTextColor ] ;
737
719
}
738
- }
720
+ }
0 commit comments