@@ -20,16 +20,26 @@ const isPhone = Device.deviceType === 'Phone';
20
20
@NativeClass
21
21
class MDTabBarControllerImpl extends UITabBarController {
22
22
private _owner : WeakRef < BottomNavigation > ;
23
+ private _preventTraitCollectionChanges : boolean ;
23
24
24
25
public static initWithOwner ( owner : WeakRef < BottomNavigation > ) : MDTabBarControllerImpl {
25
26
const handler = MDTabBarControllerImpl . alloc ( ) . init ( ) as MDTabBarControllerImpl ;
26
27
handler . _owner = owner ;
28
+ handler . _preventTraitCollectionChanges = false ;
27
29
28
30
return handler ;
29
31
}
30
32
31
33
public viewDidLoad ( ) {
32
34
super . viewDidLoad ( ) ;
35
+ if ( SDK_VERSION >= 18 ) {
36
+ try {
37
+ this . _preventTraitCollectionChanges = true ;
38
+ this . traitOverrides . horizontalSizeClass = UIUserInterfaceSizeClass . Compact ;
39
+ } finally {
40
+ this . _preventTraitCollectionChanges = false ;
41
+ }
42
+ }
33
43
this . tabBar . backgroundColor = new Color ( '#fff' ) . ios ;
34
44
}
35
45
@@ -61,9 +71,12 @@ class MDTabBarControllerImpl extends UITabBarController {
61
71
62
72
public viewWillTransitionToSizeWithTransitionCoordinator ( size : CGSize , coordinator : UIViewControllerTransitionCoordinator ) : void {
63
73
super . viewWillTransitionToSizeWithTransitionCoordinator ( size , coordinator ) ;
74
+ if ( ! this . _owner ?. get ( ) ) {
75
+ return ;
76
+ }
64
77
coordinator . animateAlongsideTransitionCompletion ( ( ) => {
65
- const owner = this . _owner . get ( ) ;
66
- if ( owner && owner . tabStrip && owner . tabStrip . items ) {
78
+ const owner = this . _owner ? .get ( ) ;
79
+ if ( owner ? .tabStrip ? .items ) {
67
80
const tabStrip = owner . tabStrip ;
68
81
tabStrip . items . forEach ( ( tabStripItem ) => {
69
82
updateBackgroundPositions ( tabStrip , tabStripItem ) ;
@@ -79,14 +92,13 @@ class MDTabBarControllerImpl extends UITabBarController {
79
92
// Mind implementation for other controllers
80
93
public traitCollectionDidChange ( previousTraitCollection : UITraitCollection ) : void {
81
94
super . traitCollectionDidChange ( previousTraitCollection ) ;
95
+ if ( this . _preventTraitCollectionChanges ) {
96
+ return ;
97
+ }
82
98
83
99
if ( SDK_VERSION >= 13 ) {
84
- const owner = this . _owner . get ( ) ;
85
- if (
86
- owner &&
87
- this . traitCollection . hasDifferentColorAppearanceComparedToTraitCollection &&
88
- this . traitCollection . hasDifferentColorAppearanceComparedToTraitCollection ( previousTraitCollection )
89
- ) {
100
+ const owner = this . _owner ?. get ( ) ;
101
+ if ( owner && this . traitCollection . hasDifferentColorAppearanceComparedToTraitCollection ?.( previousTraitCollection ) ) {
90
102
owner . notify ( {
91
103
eventName : IOSHelper . traitCollectionColorAppearanceChangedEvent ,
92
104
object : owner
0 commit comments