Skip to content

Commit

Permalink
fix(panel): fix panel close routine if it was closed immediately (#4127)
Browse files Browse the repository at this point in the history
fixes #4108 (again)

In practice, the time until the transition start is variable depending on
the browser, amongst other things. Android + Chrome is between 27 => 44ms
with a fast phone, but can take longer under many circumstances.

This removes the hardcoded time and instead looks for the transition start.
  • Loading branch information
peitschie committed Feb 2, 2023
1 parent c9115b2 commit 74aa9d8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/components/panel/panel-class.js
Expand Up @@ -289,7 +289,7 @@ class Panel extends Framework7Class {
onOpen(modifyHtmlClasses = true) {
const panel = this;
// eslint-disable-next-line
panel._openTimeStamp = new Date().getTime();
panel._openTransitionStarted = false;
const app = panel.app;

panel.opened = true;
Expand Down Expand Up @@ -442,6 +442,13 @@ class Panel extends Framework7Class {
}
const transitionEndTarget = effect === 'reveal' ? $viewEl : $el;

function panelTransitionStart() {
transitionEndTarget.transitionStart(() => {
// eslint-disable-next-line
panel._openTransitionStarted = true;
});
}

function panelTransitionEnd() {
transitionEndTarget.transitionEnd((e) => {
if ($(e.target).is(transitionEndTarget)) {
Expand All @@ -457,6 +464,7 @@ class Panel extends Framework7Class {
if ($backdropEl) {
$backdropEl.removeClass('not-animated');
}
panelTransitionStart();
panelTransitionEnd();
$el.removeClass('panel-out not-animated').addClass('panel-in');
panel.onOpen();
Expand Down Expand Up @@ -488,8 +496,7 @@ class Panel extends Framework7Class {
}
const transitionEndTarget = effect === 'reveal' ? $viewEl : $el;
// eslint-disable-next-line
const openTimeDiff = new Date().getTime() - panel._openTimeStamp;
if (openTimeDiff < 16) {
if (!panel._openTransitionStarted) {
// eslint-disable-next-line
animate = false;
}
Expand Down

0 comments on commit 74aa9d8

Please sign in to comment.