Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More natural swipe animations. #19

Merged
merged 4 commits into from
Nov 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 43 additions & 48 deletions src/swipe-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }));
zanna-37 marked this conversation as resolved.
Show resolved Hide resolved

} 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;
zanna-37 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}
Expand Down