@@ -419,9 +419,12 @@ function iterateIndexRange(index: number, eps: number, lastIndex: number, callba
419
419
}
420
420
421
421
function updateBackgroundPositions ( tabStrip : TabStrip , tabStripItem : TabStripItem , color : UIColor = null ) {
422
+ if ( ! tabStrip . nativeView || tabStripItem . _index === undefined ) {
423
+ return ;
424
+ }
422
425
let bgView = ( tabStripItem as any ) . bgView ;
423
426
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 ) ;
425
428
const frame = CGRectMake ( width * index , 0 , width , tabStrip . nativeView . frame . size . width ) ;
426
429
if ( ! bgView ) {
427
430
bgView = UIView . alloc ( ) . initWithFrame ( frame ) ;
@@ -926,7 +929,11 @@ export class Tabs extends TabsBase {
926
929
}
927
930
928
931
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 ;
930
937
}
931
938
932
939
private equalUIColor ( first : UIColor , second : UIColor ) : boolean {
@@ -952,7 +959,7 @@ export class Tabs extends TabsBase {
952
959
}
953
960
954
961
public setTabBarItemBackgroundColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
955
- if ( ! this . tabStrip || ! tabStripItem ) {
962
+ if ( ! this . tabStrip || ! tabStripItem || ! tabStripItem . nativeView ) {
956
963
return ;
957
964
}
958
965
@@ -996,6 +1003,10 @@ export class Tabs extends TabsBase {
996
1003
}
997
1004
998
1005
private setIconColor ( tabStripItem : TabStripItem , forceReload = false ) : void {
1006
+ const nativeView = tabStripItem . nativeView ;
1007
+ if ( ! nativeView ) {
1008
+ return ;
1009
+ }
999
1010
// if there is no change in the css color and there is no item color set
1000
1011
// we don't need to reload the icon
1001
1012
if ( ! forceReload && ! this . _selectedItemColor && ! this . _unSelectedItemColor ) {
@@ -1004,17 +1015,15 @@ export class Tabs extends TabsBase {
1004
1015
1005
1016
// if selectedItemColor or unSelectedItemColor is set we don't respect the color from the style
1006
1017
1007
- if ( this . _selectedItemColor ) {
1018
+ if ( this . _selectedItemColor ) {
1008
1019
const image = this . getIcon ( tabStripItem , this . _selectedItemColor ) ;
1009
- tabStripItem . nativeView . selectedImage = image ;
1010
-
1020
+ nativeView . selectedImage = image ;
1011
1021
}
1012
1022
1013
- if ( this . _unSelectedItemColor ) {
1023
+ if ( this . _unSelectedItemColor ) {
1014
1024
const image = this . getIcon ( tabStripItem , this . _unSelectedItemColor ) ;
1015
- tabStripItem . nativeView . image = image ;
1025
+ nativeView . image = image ;
1016
1026
}
1017
-
1018
1027
}
1019
1028
1020
1029
public setTabBarIconColor ( tabStripItem : TabStripItem , value : UIColor | Color ) : void {
0 commit comments