@@ -392,9 +392,21 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
392392 const nextViewControllerIndex = ownerViewControllers . indexOf ( nextViewController ) ;
393393
394394 if ( selectedIndex !== nextViewControllerIndex ) {
395+ // let s not animate again on selectedIndex change
396+ // or it will create weird behaviors
397+ owner . _animateNextChange = false ;
395398 owner . selectedIndex = nextViewControllerIndex ;
396399 owner . _canSelectItem = true ;
397400 }
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+ }
398410 }
399411}
400412
@@ -475,6 +487,9 @@ export class Tabs extends TabsBase {
475487 private _unSelectedItemColor : Color ;
476488 public animationEnabled : boolean ;
477489
490+ public _needsCacheUpdate = false ;
491+ public _animateNextChange = true ;
492+
478493 constructor ( ) {
479494 super ( ) ;
480495
@@ -740,10 +755,19 @@ export class Tabs extends TabsBase {
740755 this . viewController . tabBar . items = NSArray . arrayWithArray ( this . tabBarItems ) ;
741756 // TODO: investigate why this call is necessary to actually toggle item appearance
742757 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 ) ;
747771 }
748772 }
749773
@@ -1119,27 +1143,29 @@ export class Tabs extends TabsBase {
11191143 this . _setCanBeLoaded ( value ) ;
11201144 this . _loadUnloadTabItems ( value ) ;
11211145 } ;
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 {
11351160 doneAnimating ( ) ;
1136- } ) ;
1137- } else {
1138- doneAnimating ( ) ;
1161+ }
11391162 }
1140- }
1141- } )
1142- ) ;
1163+ } ) ;
1164+ } ) ;
1165+ } else {
1166+ this . _animateNextChange = true ;
1167+ doneAnimating ( ) ;
1168+ }
11431169
11441170 if ( this . tabBarItems && this . tabBarItems . length && this . viewController && this . viewController . tabBar ) {
11451171 this . viewController . tabBar . setSelectedItemAnimated ( this . tabBarItems [ value ] , this . animationEnabled ) ;
@@ -1159,7 +1185,6 @@ export class Tabs extends TabsBase {
11591185 ( item as any ) . index = i ;
11601186 } ) ;
11611187 }
1162-
11631188 this . setViewControllers ( value ) ;
11641189 selectedIndexProperty . coerce ( this ) ;
11651190 }
0 commit comments