@@ -392,9 +392,21 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
392
392
const nextViewControllerIndex = ownerViewControllers . indexOf ( nextViewController ) ;
393
393
394
394
if ( selectedIndex !== nextViewControllerIndex ) {
395
+ // let s not animate again on selectedIndex change
396
+ // or it will create weird behaviors
397
+ owner . _animateNextChange = false ;
395
398
owner . selectedIndex = nextViewControllerIndex ;
396
399
owner . _canSelectItem = true ;
397
400
}
401
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
402
+ if ( owner . _needsCacheUpdate ) {
403
+ invokeOnRunLoop ( ( ) => {
404
+ owner . _needsCacheUpdate = false ;
405
+ const viewController = owner . viewController ;
406
+ viewController . dataSource = null ;
407
+ viewController . dataSource = ( owner as any ) . _dataSource ;
408
+ } ) ;
409
+ }
398
410
}
399
411
}
400
412
@@ -475,6 +487,9 @@ export class Tabs extends TabsBase {
475
487
private _unSelectedItemColor : Color ;
476
488
public animationEnabled : boolean ;
477
489
490
+ public _needsCacheUpdate = false ;
491
+ public _animateNextChange = true ;
492
+
478
493
constructor ( ) {
479
494
super ( ) ;
480
495
@@ -740,10 +755,19 @@ export class Tabs extends TabsBase {
740
755
this . viewController . tabBar . items = NSArray . arrayWithArray ( this . tabBarItems ) ;
741
756
// TODO: investigate why this call is necessary to actually toggle item appearance
742
757
this . viewController . tabBar . sizeToFit ( ) ;
743
- if ( this . selectedIndex ) {
744
- console . log ( 'setSelectedItemAnimated' , this . selectedIndex ) ;
745
- this . viewController . tabBar . setSelectedItemAnimated ( this . tabBarItems [ this . selectedIndex ] , false ) ;
746
- }
758
+ // if (this.selectedIndex) {
759
+ this . viewController . tabBar . setSelectedItemAnimated ( this . tabBarItems [ this . selectedIndex ] , false ) ;
760
+ // }
761
+ }
762
+ }
763
+
764
+ public onItemsChanged ( oldItems : TabContentItem [ ] , newItems : TabContentItem [ ] ) : void {
765
+ this . _needsCacheUpdate = true ;
766
+ super . onItemsChanged ( oldItems , newItems ) ;
767
+ if ( oldItems ) {
768
+ this . _canSelectItem = true ;
769
+ this . _setCanBeLoaded ( this . selectedIndex ) ;
770
+ this . _loadUnloadTabItems ( this . selectedIndex ) ;
747
771
}
748
772
}
749
773
@@ -1119,27 +1143,29 @@ export class Tabs extends TabsBase {
1119
1143
this . _setCanBeLoaded ( value ) ;
1120
1144
this . _loadUnloadTabItems ( value ) ;
1121
1145
} ;
1122
-
1123
- invokeOnRunLoop ( ( ) =>
1124
- this . viewController . setViewControllersDirectionAnimatedCompletion ( controllers , navigationDirection , this . animationEnabled , ( finished : boolean ) => {
1125
- if ( finished ) {
1126
- if ( this . animationEnabled ) {
1127
- // HACK: UIPageViewController fix; see https://stackoverflow.com/a/17330606
1128
- // Prior Hack fails on iOS 10.3 during tests with v8 engine...
1129
- // Leaving the above link in case we need to special case this for only iOS > 10.3?
1130
-
1131
- // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
1132
- invokeOnRunLoop ( ( ) => {
1133
- this . viewController . dataSource = null ;
1134
- ( this . viewController as any ) . dataSource = this . viewController ;
1146
+ if ( this . _animateNextChange ) {
1147
+ invokeOnRunLoop ( ( ) => {
1148
+ this . viewController . setViewControllersDirectionAnimatedCompletion ( controllers , navigationDirection , this . animationEnabled , ( finished : boolean ) => {
1149
+ if ( finished ) {
1150
+ if ( this . animationEnabled ) {
1151
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/a/17330606
1152
+ // Prior Hack fails on iOS 10.3 during tests with v8 engine...
1153
+ // Leaving the above link in case we need to special case this for only iOS > 10.3?
1154
+
1155
+ // HACK: UIPageViewController fix; see https://stackoverflow.com/questions/15325891
1156
+ invokeOnRunLoop ( ( ) => {
1157
+ doneAnimating ( ) ;
1158
+ } ) ;
1159
+ } else {
1135
1160
doneAnimating ( ) ;
1136
- } ) ;
1137
- } else {
1138
- doneAnimating ( ) ;
1161
+ }
1139
1162
}
1140
- }
1141
- } )
1142
- ) ;
1163
+ } ) ;
1164
+ } ) ;
1165
+ } else {
1166
+ this . _animateNextChange = true ;
1167
+ doneAnimating ( ) ;
1168
+ }
1143
1169
1144
1170
if ( this . tabBarItems && this . tabBarItems . length && this . viewController && this . viewController . tabBar ) {
1145
1171
this . viewController . tabBar . setSelectedItemAnimated ( this . tabBarItems [ value ] , this . animationEnabled ) ;
@@ -1159,7 +1185,6 @@ export class Tabs extends TabsBase {
1159
1185
( item as any ) . index = i ;
1160
1186
} ) ;
1161
1187
}
1162
-
1163
1188
this . setViewControllers ( value ) ;
1164
1189
selectedIndexProperty . coerce ( this ) ;
1165
1190
}
0 commit comments