Skip to content

Commit 6ccc656

Browse files
MOBILE-3275 tabs: Fix course area tabs are too short when text size increased
1 parent ad85ded commit 6ccc656

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/components/tabs/tabs.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import { Subscription } from 'rxjs';
2222
import { CoreDomUtilsProvider } from '@providers/utils/dom';
2323
import { CoreAppProvider } from '@providers/app';
2424
import { CoreTabComponent } from './tab';
25+
import { CoreConfigProvider } from '@providers/config';
26+
import { CoreConstants } from '@core/constants';
27+
import { CoreConfigConstants } from '../../configconstants';
2528

2629
/**
2730
* This component displays some tabs that usually share data between them.
@@ -46,6 +49,10 @@ import { CoreTabComponent } from './tab';
4649
templateUrl: 'core-tabs.html'
4750
})
4851
export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {
52+
53+
// Minimum tab's width to display fully the word "Competencies" which is the longest tab in the app.
54+
static MIN_TAB_WIDTH = 107;
55+
4956
@Input() selectedIndex = 0; // Index of the tab to select.
5057
@Input() hideUntil = true; // Determine when should the contents be shown.
5158
@Input() parentScrollable = false; // Determine if the scroll should be in the parent content or the tab itself.
@@ -85,7 +92,8 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
8592
protected languageChangedSubscription: Subscription;
8693

8794
constructor(element: ElementRef, protected content: Content, protected domUtils: CoreDomUtilsProvider,
88-
protected appProvider: CoreAppProvider, platform: Platform, translate: TranslateService) {
95+
protected appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, platform: Platform,
96+
translate: TranslateService) {
8997
this.tabBarElement = element.nativeElement;
9098

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

226-
this.calculateMaxSlides();
227-
this.updateSlides();
234+
this.calculateMaxSlides().then(() => {
235+
this.updateSlides();
236+
});
228237
}
229238

230239
/**
@@ -376,18 +385,25 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
376385
}, 400);
377386
}
378387

379-
protected calculateMaxSlides(): void {
380-
if (this.slides) {
381-
const width = this.domUtils.getElementWidth(this.slides.getNativeElement()) || this.slides.renderedWidth;
382-
383-
if (width) {
384-
this.maxSlides = Math.floor(width / 100);
385-
386-
return;
388+
protected calculateMaxSlides(): Promise<void> {
389+
return new Promise<void>((resolve, reject): void => {
390+
this.maxSlides = 3;
391+
if (this.slides) {
392+
const width = this.domUtils.getElementWidth(this.slides.getNativeElement()) || this.slides.renderedWidth;
393+
if (width) {
394+
this.configProvider.get(CoreConstants.SETTINGS_FONT_SIZE, CoreConfigConstants.font_sizes[0].toString()).
395+
then((fontSize) => {
396+
this.maxSlides = Math.floor(width / (fontSize / CoreConfigConstants.font_sizes[0] *
397+
CoreTabsComponent.MIN_TAB_WIDTH));
398+
resolve();
399+
});
400+
} else {
401+
resolve();
402+
}
403+
} else {
404+
resolve();
387405
}
388-
}
389-
390-
this.maxSlides = 3;
406+
});
391407
}
392408

393409
/**

0 commit comments

Comments
 (0)