diff --git a/src/swipe-navigation.ts b/src/swipe-navigation.ts index 6a3f606..5a4f4e4 100644 --- a/src/swipe-navigation.ts +++ b/src/swipe-navigation.ts @@ -459,7 +459,7 @@ class swipeManager { logd("Ignoring touch: multiple touchpoints detected."); return; // Ignore swipe: Multitouch detected } - + if (typeof event.composedPath() == "object") { for (const element of event.composedPath()) { if (element instanceof Element) { @@ -577,56 +577,51 @@ class swipeManager { const tabs = this.#getTabsArray(); if (view != null) { - if (Config.animate == "swipe") { - const _in = directionLeft ? `${screen.width / 1.5}px` : `-${screen.width / 1.5}px`; - const _out = directionLeft ? `-${screen.width / 1.5}px` : `${screen.width / 1.5}px`; - view.style.transitionDuration = "200ms"; - view.style.opacity = "0"; - view.style.transform = `translate(${_in}, 0)`; - view.style.transition = "transform 0.20s, opacity 0.18s"; - setTimeout(function () { - tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); - view.style.transitionDuration = "0ms"; - view.style.transform = `translate(${_out}, 0)`; - view.style.transition = "transform 0s"; - }, 210); - setTimeout(function () { - view.style.transitionDuration = "200ms"; - view.style.opacity = "1"; - view.style.transform = "translate(0px, 0)"; - view.style.transition = "transform 0.20s, opacity 0.18s"; - }, 250); - } else if (Config.animate == "fade") { - view.style.transitionDuration = "200ms"; - view.style.transition = "opacity 0.20s"; - view.style.opacity = "0"; - setTimeout(function () { - tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); - view.style.transitionDuration = "0ms"; + + if (Config.animate == "none") { + tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); + + } else { + const duration = 200; + view.style.transition = `transform ${duration}ms ease-in, opacity ${duration}ms ease-in`; + + if (Config.animate == "swipe") { + const _in = directionLeft ? `${screen.width / 2}px` : `-${screen.width / 2}px`; + const _out = directionLeft ? `-${screen.width / 2}px` : `${screen.width / 2}px`; view.style.opacity = "0"; - view.style.transition = "opacity 0s"; - }, 210); - setTimeout(function () { - view.style.transitionDuration = "200ms"; - view.style.transition = "opacity 0.20s"; - view.style.opacity = "1"; - }, 250); - } else if (Config.animate == "flip") { - view.style.transitionDuration = "200ms"; - view.style.transform = "rotatey(90deg)"; - view.style.transition = "transform 0.20s, opacity 0.20s"; - view.style.opacity = "0.25"; - setTimeout(function () { - tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); - }, 210); + view.style.transform = `translate(${_in}, 0)`; + setTimeout(function () { + view.style.transition = ""; + view.style.transform = `translate(${_out}, 0)`; + tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); + }, duration + 10); + + } else if (Config.animate == "fade") { + view.style.opacity = "0"; + setTimeout(function () { + view.style.transition = ""; + tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); + view.style.opacity = "0"; + }, duration + 10); + + } else if (Config.animate == "flip") { + view.style.transform = "rotatey(90deg)"; + view.style.opacity = "0.25"; + setTimeout(function () { + view.style.transition = ""; + tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); + }, duration + 10); + + } else { + const exhaustiveCheck: never = Config.animate; + throw new Error(`Unhandled case: ${exhaustiveCheck}`); + } + setTimeout(function () { - view.style.transitionDuration = "200ms"; - view.style.transform = "rotatey(0deg)"; - view.style.transition = "transform 0.20s, opacity 0.20s"; + view.style.transition = `transform ${duration}ms ease-out, opacity ${duration}ms ease-out`; view.style.opacity = "1"; - }, 250); - } else { - tabs[index].dispatchEvent(new MouseEvent("click", { bubbles: false, cancelable: true })); + view.style.transform = ""; + }, duration + 50); } } }