Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Subscription } from 'rxjs';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreAppProvider } from '@providers/app';
import { CoreTabComponent } from './tab';
import { CoreConfigProvider } from '@providers/config';
import { CoreConstants } from '@core/constants';
import { CoreConfigConstants } from '../../configconstants';

/**
* This component displays some tabs that usually share data between them.
Expand All @@ -46,6 +49,10 @@ import { CoreTabComponent } from './tab';
templateUrl: 'core-tabs.html'
})
export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {

// Minimum tab's width to display fully the word "Competencies" which is the longest tab in the app.
static MIN_TAB_WIDTH = 107;

@Input() selectedIndex = 0; // Index of the tab to select.
@Input() hideUntil = true; // Determine when should the contents be shown.
@Input() parentScrollable = false; // Determine if the scroll should be in the parent content or the tab itself.
Expand Down Expand Up @@ -85,7 +92,8 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
protected languageChangedSubscription: Subscription;

constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider,
protected appProvider: CoreAppProvider, platform: Platform, translate: TranslateService) {
protected appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, platform: Platform,
translate: TranslateService) {
this.tabBarElement = element.nativeElement;

this.direction = platform.isRTL ? 'rtl' : 'ltr';
Expand Down Expand Up @@ -223,8 +231,9 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
return;
}

this.calculateMaxSlides();
this.updateSlides();
this.calculateMaxSlides().then(() => {
this.updateSlides();
});
}

/**
Expand Down Expand Up @@ -376,18 +385,25 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
}, 400);
}

protected calculateMaxSlides(): void {
if (this.slides) {
const width = this.domUtils.getElementWidth(this.slides.getNativeElement()) || this.slides.renderedWidth;

if (width) {
this.maxSlides = Math.floor(width / 100);

return;
protected calculateMaxSlides(): Promise<void> {
return new Promise<void>((resolve, reject): void => {
this.maxSlides = 3;
if (this.slides) {
const width = this.domUtils.getElementWidth(this.slides.getNativeElement()) || this.slides.renderedWidth;
if (width) {
this.configProvider.get(CoreConstants.SETTINGS_FONT_SIZE, CoreConfigConstants.font_sizes[0].toString()).
then((fontSize) => {
this.maxSlides = Math.floor(width / (fontSize / CoreConfigConstants.font_sizes[0] *
CoreTabsComponent.MIN_TAB_WIDTH));
resolve();
});
} else {
resolve();
}
} else {
resolve();
}
}

this.maxSlides = 3;
});
}

/**
Expand Down