From fdd76d7100ba5b152b3330eddb90d4de712b5e36 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 17 Feb 2021 12:15:09 -0500 Subject: [PATCH 1/2] do not incorrectly show toolbar when refreshing --- core/src/components/header/header.tsx | 2 +- core/src/components/header/header.utils.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/components/header/header.tsx b/core/src/components/header/header.tsx index eaee37f9eaa..93f0e0c512b 100644 --- a/core/src/components/header/header.tsx +++ b/core/src/components/header/header.tsx @@ -120,7 +120,7 @@ export class Header implements ComponentInterface { * as well as progressively showing/hiding the main header * border as the top-most toolbar collapses or expands. */ - const toolbarIntersection = (ev: any) => { handleToolbarIntersection(ev, mainHeaderIndex, scrollHeaderIndex); }; + const toolbarIntersection = (ev: any) => { handleToolbarIntersection(ev, mainHeaderIndex, scrollHeaderIndex, this.scrollEl!); }; this.intersectionObserver = new IntersectionObserver(toolbarIntersection, { root: contentEl, threshold: [0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1] }); this.intersectionObserver.observe(scrollHeaderIndex.toolbars[scrollHeaderIndex.toolbars.length - 1].el); diff --git a/core/src/components/header/header.utils.ts b/core/src/components/header/header.utils.ts index dd6a66d2081..58c15a05d78 100644 --- a/core/src/components/header/header.utils.ts +++ b/core/src/components/header/header.utils.ts @@ -72,7 +72,7 @@ export const setToolbarBackgroundOpacity = (toolbar: ToolbarIndex, opacity?: num } }; -const handleToolbarBorderIntersection = (ev: any, mainHeaderIndex: HeaderIndex) => { +const handleToolbarBorderIntersection = (ev: any, mainHeaderIndex: HeaderIndex, scrollTop: number) => { if (!ev[0].isIntersecting) { return; } /** @@ -80,8 +80,13 @@ const handleToolbarBorderIntersection = (ev: any, mainHeaderIndex: HeaderIndex) * does not always reset the scrollTop position to 0 when letting go. It will * set to 1 once the rubber band effect has ended. This causes the background to * appear slightly on certain app setups. + * + * Additionally, we check if user is rubber banding (scrolling is negative) + * as this can mean they are using pull to refresh. Once the refresher starts, + * the content is transformed which can cause the intersection observer to erroneously + * fire here as well. */ - const scale = (ev[0].intersectionRatio > 0.9) ? 0 : ((1 - ev[0].intersectionRatio) * 100) / 75; + const scale = (ev[0].intersectionRatio > 0.9 || scrollTop <= 0) ? 0 : ((1 - ev[0].intersectionRatio) * 100) / 75; mainHeaderIndex.toolbars.forEach(toolbar => { setToolbarBackgroundOpacity(toolbar, (scale === 1) ? undefined : scale); @@ -93,9 +98,9 @@ const handleToolbarBorderIntersection = (ev: any, mainHeaderIndex: HeaderIndex) * and show the primary toolbar content. If the toolbars are not intersecting, * hide the primary toolbar content and show the scrollable toolbar content */ -export const handleToolbarIntersection = (ev: any, mainHeaderIndex: HeaderIndex, scrollHeaderIndex: HeaderIndex) => { +export const handleToolbarIntersection = (ev: any, mainHeaderIndex: HeaderIndex, scrollHeaderIndex: HeaderIndex, scrollEl: HTMLElement) => { writeTask(() => { - handleToolbarBorderIntersection(ev, mainHeaderIndex); + handleToolbarBorderIntersection(ev, mainHeaderIndex, scrollEl.scrollTop); const event = ev[0]; From 927031083a099b54edfe37c80ea985d4d2ed3ac7 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 17 Feb 2021 12:38:37 -0500 Subject: [PATCH 2/2] one more bug fix --- core/src/components/header/header.utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/components/header/header.utils.ts b/core/src/components/header/header.utils.ts index 58c15a05d78..2df31003b82 100644 --- a/core/src/components/header/header.utils.ts +++ b/core/src/components/header/header.utils.ts @@ -100,7 +100,8 @@ const handleToolbarBorderIntersection = (ev: any, mainHeaderIndex: HeaderIndex, */ export const handleToolbarIntersection = (ev: any, mainHeaderIndex: HeaderIndex, scrollHeaderIndex: HeaderIndex, scrollEl: HTMLElement) => { writeTask(() => { - handleToolbarBorderIntersection(ev, mainHeaderIndex, scrollEl.scrollTop); + const scrollTop = scrollEl.scrollTop; + handleToolbarBorderIntersection(ev, mainHeaderIndex, scrollTop); const event = ev[0]; @@ -132,7 +133,7 @@ export const handleToolbarIntersection = (ev: any, mainHeaderIndex: HeaderIndex, const hasValidIntersection = (intersection.x === 0 && intersection.y === 0) || (intersection.width !== 0 && intersection.height !== 0); - if (hasValidIntersection) { + if (hasValidIntersection && scrollTop > 0) { setHeaderActive(mainHeaderIndex); setHeaderActive(scrollHeaderIndex, false); setToolbarBackgroundOpacity(mainHeaderIndex.toolbars[0]);