@@ -419,9 +419,12 @@ function iterateIndexRange(index: number, eps: number, lastIndex: number, callba
419419}
420420
421421function updateBackgroundPositions ( tabStrip : TabStrip , tabStripItem : TabStripItem , color : UIColor = null ) {
422+ if ( ! tabStrip . nativeView || tabStripItem . _index === undefined ) {
423+ return ;
424+ }
422425 let bgView = ( tabStripItem as any ) . bgView ;
423426 const index = tabStripItem . _index ;
424- const width = tabStrip . nativeView . frame . size . width / tabStrip . items . length ;
427+ const width = tabStrip . nativeView . frame . size . width / ( tabStrip . items . filter ( s => s . _index !== undefined ) . length ) ;
425428 const frame = CGRectMake ( width * index , 0 , width , tabStrip . nativeView . frame . size . width ) ;
426429 if ( ! bgView ) {
427430 bgView = UIView . alloc ( ) . initWithFrame ( frame ) ;
@@ -926,7 +929,11 @@ export class Tabs extends TabsBase {
926929 }
927930
928931 public setTabBarItemTitle ( tabStripItem : TabStripItem , value : string ) : void {
929- tabStripItem . nativeView . title = value ;
932+ const nativeView = tabStripItem . nativeView ;
933+ if ( ! nativeView ) {
934+ return ;
935+ }
936+ nativeView . title = value ;
930937 }
931938
932939 private equalUIColor ( first : UIColor , second : UIColor ) : boolean {
@@ -952,7 +959,7 @@ export class Tabs extends TabsBase {
952959 }
953960
954961 public setTabBarItemBackgroundColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
955- if ( ! this . tabStrip || ! tabStripItem ) {
962+ if ( ! this . tabStrip || ! tabStripItem || ! tabStripItem . nativeView ) {
956963 return ;
957964 }
958965
@@ -996,6 +1003,10 @@ export class Tabs extends TabsBase {
9961003 }
9971004
9981005 private setIconColor ( tabStripItem : TabStripItem , forceReload = false ) : void {
1006+ const nativeView = tabStripItem . nativeView ;
1007+ if ( ! nativeView ) {
1008+ return ;
1009+ }
9991010 // if there is no change in the css color and there is no item color set
10001011 // we don't need to reload the icon
10011012 if ( ! forceReload && ! this . _selectedItemColor && ! this . _unSelectedItemColor ) {
@@ -1004,17 +1015,15 @@ export class Tabs extends TabsBase {
10041015
10051016 // if selectedItemColor or unSelectedItemColor is set we don't respect the color from the style
10061017
1007- if ( this . _selectedItemColor ) {
1018+ if ( this . _selectedItemColor ) {
10081019 const image = this . getIcon ( tabStripItem , this . _selectedItemColor ) ;
1009- tabStripItem . nativeView . selectedImage = image ;
1010-
1020+ nativeView . selectedImage = image ;
10111021 }
10121022
1013- if ( this . _unSelectedItemColor ) {
1023+ if ( this . _unSelectedItemColor ) {
10141024 const image = this . getIcon ( tabStripItem , this . _unSelectedItemColor ) ;
1015- tabStripItem . nativeView . image = image ;
1025+ nativeView . image = image ;
10161026 }
1017-
10181027 }
10191028
10201029 public setTabBarIconColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
0 commit comments