MOBILE-2455 tabs: Slide to selected tab if needed
parent
4f636824e3
commit
f2a6a2fb10
|
@ -70,6 +70,8 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
|
||||||
protected resizeFunction;
|
protected resizeFunction;
|
||||||
protected isDestroyed = false;
|
protected isDestroyed = false;
|
||||||
protected isCurrentView = true;
|
protected isCurrentView = true;
|
||||||
|
protected shouldSlideToInitial = false; // Whether we need to slide to the initial slide because it's out of view.
|
||||||
|
protected hasSliddenToInitial = false; // Whether we've already slidden to the initial slide or there was no need.
|
||||||
|
|
||||||
constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider) {
|
constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider) {
|
||||||
this.tabBarElement = element.nativeElement;
|
this.tabBarElement = element.nativeElement;
|
||||||
|
@ -265,6 +267,11 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
|
||||||
this.showPrevButton = false;
|
this.showPrevButton = false;
|
||||||
this.showNextButton = this.numTabsShown > this.slidesShown;
|
this.showNextButton = this.numTabsShown > this.slidesShown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.shouldSlideToInitial && currentIndex != this.selected) {
|
||||||
|
// Current tab has changed, don't slide to initial anymore.
|
||||||
|
this.shouldSlideToInitial = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -282,6 +289,20 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.slides.update();
|
this.slides.update();
|
||||||
this.slides.resize();
|
this.slides.resize();
|
||||||
|
|
||||||
|
if (!this.hasSliddenToInitial && this.selected && this.selected >= this.slidesShown) {
|
||||||
|
this.hasSliddenToInitial = true;
|
||||||
|
this.shouldSlideToInitial = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.shouldSlideToInitial) {
|
||||||
|
this.slides.slideTo(this.selected, 0);
|
||||||
|
this.shouldSlideToInitial = false;
|
||||||
|
}
|
||||||
|
}, 400);
|
||||||
|
} else if (this.selected) {
|
||||||
|
this.hasSliddenToInitial = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue