@@ -71,20 +71,19 @@ class UITabBarControllerImpl extends UITabBarController {
7171
7272 public viewWillTransitionToSizeWithTransitionCoordinator ( size : CGSize , coordinator : UIViewControllerTransitionCoordinator ) : void {
7373 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 ) ;
8887 }
8988
9089 // Mind implementation for other controllers
@@ -207,17 +206,14 @@ class UINavigationControllerDelegateImpl extends NSObject implements UINavigatio
207206
208207function updateBackgroundPositions ( tabStrip : TabStrip , tabStripItem : TabStripItem ) {
209208 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 ) ;
210212 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 ) ;
214213 bgView = UIView . alloc ( ) . initWithFrame ( frame ) ;
215214 tabStrip . nativeView . insertSubviewAtIndex ( bgView , 0 ) ;
216215 ( < any > tabStripItem ) . bgView = bgView ;
217216 } 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 ) ;
221217 bgView . frame = frame ;
222218 }
223219
@@ -376,8 +372,7 @@ export class BottomNavigation extends TabNavigationBase {
376372 }
377373
378374 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 ) ;
381376 }
382377
383378 public setTabBarIconColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
@@ -388,15 +383,23 @@ export class BottomNavigation extends TabNavigationBase {
388383 }
389384
390385 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 ) ;
393387 }
394388
395389 public setTabBarItemTextTransform ( tabStripItem : TabStripItem , value : TextTransform ) : void {
396390 const title = getTransformedText ( tabStripItem . label . text , value ) ;
397391 tabStripItem . nativeView . title = title ;
398392 }
399393
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+
400403 public onMeasure ( widthMeasureSpec : number , heightMeasureSpec : number ) : void {
401404 const width = layout . getMeasureSpecSize ( widthMeasureSpec ) ;
402405 const widthMode = layout . getMeasureSpecMode ( widthMeasureSpec ) ;
@@ -518,8 +521,7 @@ export class BottomNavigation extends TabNavigationBase {
518521 const tabBarItem = this . createTabBarItem ( tabStripItem , i ) ;
519522 updateTitleAndIconPositions ( tabStripItem , tabBarItem , controller ) ;
520523
521- const states = getTitleAttributesForStates ( tabStripItem . label ) ;
522- applyStatesToItem ( tabBarItem , states , this . viewController . tabBar ) ;
524+ setViewTextAttributes ( tabBarItem , tabStripItem . label , this . viewController . tabBar ) ;
523525
524526 controller . tabBarItem = tabBarItem ;
525527 tabStripItem . _index = i ;
@@ -688,51 +690,31 @@ export class BottomNavigation extends TabNavigationBase {
688690 }
689691}
690692
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 {
697694 if ( ! view ) {
698695 return null ;
699696 }
700697
701- const result : TabStates = { } ;
702698 const defaultTabItemFontSize = 10 ;
703699 const tabItemFontSize = view . style . fontSize || defaultTabItemFontSize ;
704700 const font : UIFont = view . style . fontInternal . getUIFont ( UIFont . systemFontOfSize ( tabItemFontSize ) ) ;
705701 const tabItemTextColor = view . style . color ;
706702 const textColor = tabItemTextColor instanceof Color ? tabItemTextColor . ios : null ;
707- result . normalState = { [ NSFontAttributeName ] : font } ;
703+ let attributes : any = { [ NSFontAttributeName ] : font } ;
708704 if ( textColor ) {
709- result . normalState [ UITextAttributeTextColor ] = textColor ;
705+ attributes [ UITextAttributeTextColor ] = textColor ;
706+ attributes [ NSForegroundColorAttributeName ] = textColor ;
710707 }
711708
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 ) ;
729711
730712 // there's a bug when setting the item color on ios 13 if there's no background set to the tabstrip
731713 // https://books.google.bg/books?id=99_BDwAAQBAJ&q=tabBar.unselectedItemTintColor
732714 // to fix the above issue we are applying the selected fix only for the case, when there is no background set
733715 // in that case we have the following known issue:
734716 // 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 ] ;
737719 }
738- }
720+ }
0 commit comments