mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
fix(mobile): sidebar shown on taps
This commit is contained in:
parent
aad5b6cdbd
commit
73828a195b
@ -1,5 +1,9 @@
|
||||
import FlexContainer from "../containers/flex_container.js";
|
||||
|
||||
const DRAG_STATE_NONE = 0;
|
||||
const DRAG_STATE_INITIAL_DRAG = 1;
|
||||
const DRAG_STATE_DRAGGING = 2;
|
||||
|
||||
export default class SidebarContainer extends FlexContainer {
|
||||
|
||||
constructor(screenName, direction) {
|
||||
@ -7,6 +11,7 @@ export default class SidebarContainer extends FlexContainer {
|
||||
|
||||
this.screenName = screenName;
|
||||
this.currentTranslate = -100;
|
||||
this.dragState = DRAG_STATE_NONE;
|
||||
}
|
||||
|
||||
doRender() {
|
||||
@ -32,37 +37,40 @@ export default class SidebarContainer extends FlexContainer {
|
||||
}
|
||||
|
||||
const x = e.touches ? e.touches[0].clientX : e.clientX;
|
||||
|
||||
if (x > 30 && this.currentTranslate === -100) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isDragging = true;
|
||||
this.startX = x;
|
||||
|
||||
this.sidebarContainer.style.zIndex = 1000;
|
||||
|
||||
this.originalTransition = this.sidebarWrapper.style.transition;
|
||||
this.sidebarWrapper.style.transition = "none";
|
||||
|
||||
e.preventDefault();
|
||||
this.dragState = DRAG_STATE_INITIAL_DRAG;
|
||||
}
|
||||
|
||||
#onDragMove(e) {
|
||||
if (!this.isDragging) {
|
||||
if (this.dragState === DRAG_STATE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
const x = e.touches ? e.touches[0].clientX : e.clientX;
|
||||
const deltaX = x - this.startX;
|
||||
if (this.dragState === DRAG_STATE_INITIAL_DRAG) {
|
||||
if (deltaX > 5) {
|
||||
this.sidebarContainer.style.zIndex = 1000;
|
||||
this.originalTransition = this.sidebarWrapper.style.transition;
|
||||
this.sidebarWrapper.style.transition = "none";
|
||||
this.dragState = DRAG_STATE_DRAGGING;
|
||||
}
|
||||
} else if (this.dragState === DRAG_STATE_DRAGGING) {
|
||||
const width = this.sidebarWrapper.offsetWidth;
|
||||
const translatePercentage = Math.min(0, Math.max(this.currentTranslate + (deltaX / width) * 100, -100));
|
||||
this.translatePercentage = translatePercentage;
|
||||
this.sidebarWrapper.style.transform = `translateX(${translatePercentage}%)`;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
#onDragEnd(e) {
|
||||
if (!this.isDragging) {
|
||||
if (this.dragState === DRAG_STATE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,6 +83,8 @@ export default class SidebarContainer extends FlexContainer {
|
||||
if (!isOpen) {
|
||||
this.sidebarContainer.style.zIndex = -1000;
|
||||
}
|
||||
|
||||
this.dragState = DRAG_STATE_NONE;
|
||||
}
|
||||
|
||||
activeScreenChangedEvent({activeScreen}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user