Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): make the sidebar gesture easier to press

Elian Doranf8b386e42d0a
diff --git a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts b/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
index ef719d36a9..e52c0dff49 100644
--- a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
+++ b/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
@@ -22,6 +22,7 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
private currentTranslate: number;
private dragState: number;
private startX?: number;
+ private startY?: number;
private translatePercentage: number;
private sidebarEl!: HTMLElement;
private backdropEl!: HTMLElement;
@@ -51,11 +52,13 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
#onDragStart(e: TouchEvent | MouseEvent) {
const x = "touches" in e ? e.touches[0].clientX : e.clientX;
+ const y = "touches" in e ? e.touches[0].clientY : e.clientY;
this.startX = x;
+ this.startY = y;
// Prevent dragging if too far from the edge of the screen and the menu is closed.
- let dragRefX = glob.isRtl ? this.screenWidth - x : x;
- if (dragRefX > 30 && this.currentTranslate === -100) {
+ const dragRefX = glob.isRtl ? this.screenWidth - x : x;
+ if (dragRefX > 300 && this.currentTranslate === -100) {
return;
}
@@ -65,13 +68,26 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
}
#onDragMove(e: TouchEvent | MouseEvent) {
- if (this.dragState === DRAG_STATE_NONE || !this.startX) {
+ if (this.dragState === DRAG_STATE_NONE || !this.startX || !this.startY) {
return;
}
const x = "touches" in e ? e.touches[0].clientX : e.clientX;
+ const y = "touches" in e ? e.touches[0].clientY : e.clientY;
const deltaX = glob.isRtl ? this.startX - x : x - this.startX;
+ const deltaY = y - this.startY;
+
if (this.dragState === DRAG_STATE_INITIAL_DRAG) {
+ // Check if the gesture is more horizontal than vertical
+ const absDeltaX = Math.abs(deltaX);
+ const absDeltaY = Math.abs(deltaY);
+
+ // If movement is more vertical than horizontal, cancel the drag to allow scrolling
+ if (absDeltaY > absDeltaX * 1.5) {
+ this.dragState = DRAG_STATE_NONE;
+ return;
+ }
+
if (this.currentTranslate === -100 ? deltaX > DRAG_CLOSED_START_THRESHOLD : deltaX < -DRAG_OPENED_START_THRESHOLD) {
/* Disable the transitions since they affect performance, they are going to reenabled once drag ends. */
this.sidebarEl.style.transition = "none";
@@ -89,7 +105,7 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
}
} else if (this.dragState === DRAG_STATE_DRAGGING) {
const width = this.sidebarEl.offsetWidth;
- let translatePercentage = Math.min(0, Math.max(this.currentTranslate + (deltaX / width) * 100, -100));
+ const translatePercentage = Math.min(0, Math.max(this.currentTranslate + (deltaX / width) * 100, -100));
const backdropOpacity = Math.max(0, 1 + translatePercentage / 100);
this.translatePercentage = translatePercentage;
if (glob.isRtl) {
@@ -160,12 +176,10 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
this.sidebarEl.classList.toggle("show", isOpen);
if (isOpen) {
this.sidebarEl.style.transform = "translateX(0)";
+ } else if (glob.isRtl) {
+ this.sidebarEl.style.transform = "translateX(100%)";
} else {
- if (glob.isRtl) {
- this.sidebarEl.style.transform = "translateX(100%)"
- } else {
- this.sidebarEl.style.transform = "translateX(-100%)";
- }
+ this.sidebarEl.style.transform = "translateX(-100%)";
}
this.sidebarEl.style.transition = this.originalSidebarTransition;