Skip to content

Commit e373d50

Browse files
committed
fix(tab-bar): update position and animation based on requirements
1 parent 265accb commit e373d50

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

core/src/components/tab-bar/tab-bar.ionic.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@
9494
// --------------------------------------------------
9595

9696
:host(.tab-bar-hide-on-scroll) {
97-
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
97+
transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
9898
}
9999

100100
:host(.tab-bar-scroll-hidden) {
101-
transform: translateY(calc(100% + var(--ion-safe-area-bottom, 0))) translateX(calc(-50%));
101+
transform: translateY(calc(100% + var(--ion-safe-area-bottom, 0) + globals.$ion-space-1000)) translateX(calc(-50%));
102102

103-
transition: transform 0.3s cubic-bezier(0.3, 1, 0.1, 1), opacity 0.3s cubic-bezier(0.3, 1, 0.1, 1);
104-
105-
opacity: 0;
103+
transition: transform 0.35s cubic-bezier(0.3, 1, 0.1, 1);
106104
}
107105

108106
:host([slot="top"].tab-bar-scroll-hidden) {

core/src/components/tab-bar/tab-bar.tsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,15 @@ export class TabBar implements ComponentInterface {
190190
private async initScrollListener(contentEl: HTMLElement) {
191191
const scrollEl = (this.scrollEl = await getScrollElement(contentEl));
192192

193-
const scrollThreshold = 10;
194-
195193
this.contentScrollCallback = () => {
196194
readTask(() => {
197195
const scrollTop = scrollEl.scrollTop;
198-
const isScrollingDown = scrollTop > this.lastScrollTop;
199-
200-
if (isScrollingDown !== this.lastScrollTop > this.scrollDirectionChangeTop) {
201-
this.scrollDirectionChangeTop = this.lastScrollTop;
202-
}
203-
204-
const delta = Math.abs(scrollTop - this.scrollDirectionChangeTop);
196+
const shouldHide = this.checkScrollStatus(scrollTop);
205197

206-
if (delta >= scrollThreshold) {
207-
const shouldHide = isScrollingDown && scrollTop > 0;
208-
if (shouldHide !== this.scrollHidden) {
209-
writeTask(() => {
210-
this.scrollHidden = shouldHide;
211-
});
212-
}
198+
if (shouldHide !== this.scrollHidden) {
199+
writeTask(() => {
200+
this.scrollHidden = shouldHide;
201+
});
213202
}
214203

215204
this.lastScrollTop = scrollTop;
@@ -226,6 +215,33 @@ export class TabBar implements ComponentInterface {
226215
}
227216
}
228217

218+
private checkScrollStatus(scrollTop: number): boolean {
219+
// Always visible within the first 80px of scroll
220+
const visibleZone = 80;
221+
// Hides after 60px of continuous downward scrolling only, when scrolling up threashold should be 0px
222+
const scrollThresholdHide = 60;
223+
224+
if (scrollTop <= visibleZone) {
225+
return false;
226+
}
227+
228+
const isScrollingDown = scrollTop > this.lastScrollTop;
229+
const wasScrollingDown = this.lastScrollTop > this.scrollDirectionChangeTop;
230+
231+
if (isScrollingDown !== wasScrollingDown) {
232+
this.scrollDirectionChangeTop = this.lastScrollTop;
233+
}
234+
235+
const delta = Math.abs(scrollTop - this.scrollDirectionChangeTop);
236+
const threshold = isScrollingDown ? scrollThresholdHide : 0;
237+
238+
if (delta < threshold) {
239+
return this.scrollHidden;
240+
}
241+
242+
return isScrollingDown;
243+
}
244+
229245
private getShape(): string | undefined {
230246
const theme = getIonTheme(this);
231247
const { shape } = this;

0 commit comments

Comments
 (0)