Skip to content

Commit

Permalink
Fix the pop-up backdrop issue + Faster pop-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Clooos authored Aug 10, 2024
1 parent 88e6314 commit 233fbe9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
62 changes: 31 additions & 31 deletions dist/bubble-card.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/cards/pop-up/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export function getBackdrop(context) {
document.head.appendChild(backdropCustomStyle);

const backdropElement = createElement('div', 'bubble-backdrop backdrop is-hidden');
backdropElement.style.willChange = 'all';

if (context.config.hide_backdrop) {
backdropElement.style.display = 'none';
backdropElement.style.pointerEvents = 'none';
Expand All @@ -49,6 +51,8 @@ export function getBackdrop(context) {

backdrop = { hideBackdrop, showBackdrop, backdropElement, backdropCustomStyle };

backdropElement.style.willChange = '';

return backdrop;
}

Expand Down
26 changes: 14 additions & 12 deletions src/cards/pop-up/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ export function addHash(hash) {
}

export function closePopup(context) {
const { hideBackdrop, showBackdrop } = getBackdrop(context);

if (context.popUp.classList.contains('is-popup-closed')) return;

popupCount--;
document.body.style.overflow = '';
context.popUp.classList.add('will-change');

// Clear any existing timeouts
clearTimeout(context.hideContentTimeout);
clearTimeout(context.removeDomTimeout);
clearTimeout(context.closeTimeout);

hideBackdrop();

// Hide content after delay
context.hideContentTimeout = setTimeout(() => {
context.popUp.style.display = 'none';
Expand Down Expand Up @@ -75,6 +80,7 @@ export function closePopup(context) {
}, 360);

context.popUp.classList.replace('is-popup-opened', 'is-popup-closed');
context.popUp.classList.remove('will-change');

// Execute close action if defined
if (context.config.close_action) {
Expand All @@ -83,7 +89,13 @@ export function closePopup(context) {
}

export function openPopup(context) {
const { hideBackdrop, showBackdrop } = getBackdrop(context);

if (context.popUp.classList.contains('is-popup-opened')) return;

popupCount++;
showBackdrop();
context.popUp.classList.add('will-change');

if (context.sectionRow?.tagName.toLowerCase() === 'hui-card') {
context.sectionRow.hidden = false;
Expand All @@ -100,11 +112,6 @@ export function openPopup(context) {
if (context.popUp.parentNode !== context.verticalStack) {
context.verticalStack.appendChild(context.popUp);
}

// Force a reflow to ensure the popup is fully appended and recognized by the DOM
void context.popUp.offsetWidth;

popupCount++;

// Add event listeners
context.popUp.addEventListener('touchstart', context.resetCloseTimeout, { passive: true });
Expand Down Expand Up @@ -136,22 +143,17 @@ export function openPopup(context) {
if (context.config.open_action) {
callAction(context.popUp, context.config, 'open_action');
}

context.popUp.classList.remove('will-change');
}

export function onUrlChange(context) {
const { hideBackdrop, showBackdrop } = getBackdrop(context);
return function() {
if (context.config.hash === location.hash) {
openPopup(context);
} else {
closePopup(context);
}

if (popupCount === 0 || context.editor) {
hideBackdrop();
} else {
showBackdrop();
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/cards/pop-up/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default `
}
.bubble-pop-up {
transition: transform 0.3s ease;
will-change: transform;
position: fixed;
width: 100%;
max-width: 100%;
Expand Down Expand Up @@ -130,6 +129,9 @@ export default `
mask-image: none;
-webkit-mask-image: none;
}
.will-change {
will-change: all;
}
.no-header .bubble-header-container {
visibility: hidden !important;
Expand Down
2 changes: 1 addition & 1 deletion src/var/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export let version = 'v2.2.0-beta.1';
export let version = 'v2.2.0-beta.2';

0 comments on commit 233fbe9

Please sign in to comment.