MOBILE-3320 core: Prevent flickering on tab scrolling
parent
a21c7597d7
commit
21d968c84e
|
@ -61,7 +61,6 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
numTabsShown = 0;
|
numTabsShown = 0;
|
||||||
direction = 'ltr';
|
direction = 'ltr';
|
||||||
description = '';
|
description = '';
|
||||||
lastScroll = 0;
|
|
||||||
slidesOpts = {
|
slidesOpts = {
|
||||||
initialSlide: 0,
|
initialSlide: 0,
|
||||||
slidesPerView: 3,
|
slidesPerView: 3,
|
||||||
|
@ -89,6 +88,8 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
protected slidesSwiper: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
protected slidesSwiper: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
protected slidesSwiperLoaded = false;
|
protected slidesSwiperLoaded = false;
|
||||||
protected scrollElements: Record<string | number, HTMLElement> = {}; // Scroll elements for each loaded tab.
|
protected scrollElements: Record<string | number, HTMLElement> = {}; // Scroll elements for each loaded tab.
|
||||||
|
protected lastScroll = 0;
|
||||||
|
protected previousLastScroll = 0;
|
||||||
|
|
||||||
tabAction: CoreTabsRoleTab<T>;
|
tabAction: CoreTabsRoleTab<T>;
|
||||||
|
|
||||||
|
@ -164,6 +165,7 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
this.tabBarElement!.classList.remove('tabs-hidden');
|
this.tabBarElement!.classList.remove('tabs-hidden');
|
||||||
if (scroll === 0) {
|
if (scroll === 0) {
|
||||||
this.tabBarElement!.style.height = '';
|
this.tabBarElement!.style.height = '';
|
||||||
|
this.previousLastScroll = this.lastScroll;
|
||||||
this.lastScroll = 0;
|
this.lastScroll = 0;
|
||||||
} else if (scroll !== undefined) {
|
} else if (scroll !== undefined) {
|
||||||
this.tabBarElement!.style.height = (this.tabBarHeight - scroll) + 'px';
|
this.tabBarElement!.style.height = (this.tabBarHeight - scroll) + 'px';
|
||||||
|
@ -253,18 +255,14 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.tabsShown) {
|
|
||||||
if (window.innerHeight >= CoreTabsBaseComponent.MAX_HEIGHT_TO_HIDE_TABS) {
|
if (window.innerHeight >= CoreTabsBaseComponent.MAX_HEIGHT_TO_HIDE_TABS) {
|
||||||
// Ensure tabbar is shown.
|
// Ensure tabbar is shown.
|
||||||
this.tabsShown = true;
|
this.applyScroll(true, 0);
|
||||||
this.tabBarElement?.classList.remove('tabs-hidden');
|
|
||||||
this.lastScroll = 0;
|
|
||||||
this.calculateTabBarHeight();
|
this.calculateTabBarHeight();
|
||||||
} else {
|
} else if (!this.tabsShown) {
|
||||||
// Don't recalculate.
|
// Don't recalculate.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await this.calculateMaxSlides();
|
await this.calculateMaxSlides();
|
||||||
|
|
||||||
|
@ -504,7 +502,7 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollTop == this.lastScroll) {
|
if (scrollTop == this.lastScroll || scrollTop == this.previousLastScroll) {
|
||||||
// Ensure scroll has been modified to avoid flicks.
|
// Ensure scroll has been modified to avoid flicks.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -522,6 +520,7 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use lastScroll after moving the tabs to avoid flickering.
|
// Use lastScroll after moving the tabs to avoid flickering.
|
||||||
|
this.previousLastScroll = this.lastScroll;
|
||||||
this.lastScroll = scrollTop;
|
this.lastScroll = scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue