Skip to content

Commit 066db13

Browse files
committed
fix(mobile): sidebar toggle button
1 parent 16e9d74 commit 066db13

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/public/app/widgets/mobile_widgets/sidebar_container.js

+27-17
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ export default class SidebarContainer extends FlexContainer {
3232
}
3333

3434
#onDragStart(e) {
35-
if (!this.backdropEl) {
36-
this.backdropEl = document.getElementById("mobile-sidebar-container");
37-
this.sidebarEl = document.getElementById("mobile-sidebar-wrapper");
38-
}
39-
4035
const x = e.touches ? e.touches[0].clientX : e.clientX;
4136

4237
if (x > 30 && this.currentTranslate === -100) {
4338
return;
4439
}
4540

4641
this.startX = x;
42+
this.#setInitialState();
4743
this.dragState = DRAG_STATE_INITIAL_DRAG;
4844
this.translatePercentage = 0;
4945
}
@@ -58,8 +54,6 @@ export default class SidebarContainer extends FlexContainer {
5854
if (this.dragState === DRAG_STATE_INITIAL_DRAG) {
5955
if (Math.abs(deltaX) > 5) {
6056
/* Disable the transitions since they affect performance, they are going to reenabled once drag ends. */
61-
this.originalSidebarTransition = this.sidebarEl.style.transition;
62-
this.originalBackdropTransition = this.backdropEl.style.transition;
6357
this.sidebarEl.style.transition = "none";
6458
this.backdropEl.style.transition = "none";
6559

@@ -87,25 +81,41 @@ export default class SidebarContainer extends FlexContainer {
8781
// If the sidebar is closed, snap the sidebar open only if the user swiped over a threshold.
8882
// When the sidebar is open, always close for a smooth experience.
8983
const isOpen = (this.currentTranslate === -100 && this.translatePercentage > -(100 - DRAG_THRESHOLD));
84+
this.#setSidebarOpen(isOpen);
85+
}
86+
87+
#setInitialState() {
88+
if (this.sidebarEl) {
89+
// Already initialized.
90+
return;
91+
}
92+
93+
this.sidebarEl = document.getElementById("mobile-sidebar-wrapper");
94+
this.backdropEl = document.getElementById("mobile-sidebar-container");
95+
this.originalSidebarTransition = this.sidebarEl.style.transition;
96+
this.originalBackdropTransition = this.backdropEl.style.transition;
97+
}
98+
99+
#setSidebarOpen(isOpen) {
100+
if (!this.sidebarEl) {
101+
return;
102+
}
103+
90104
this.sidebarEl.classList.toggle("show", isOpen);
91105
this.sidebarEl.style.transform = isOpen ? 'translateX(0)' : 'translateX(-100%)';
92106
this.sidebarEl.style.transition = this.originalSidebarTransition;
93-
this.backdropEl.style.transition = this.originalBackdropTransition;
94-
this.currentTranslate = isOpen ? 0 : -100;
95107

96-
if (!isOpen) {
97-
this.backdropEl.classList.remove("show");
98-
}
108+
this.backdropEl.classList.toggle("show", isOpen);
109+
this.backdropEl.style.transition = this.originalBackdropTransition;
110+
this.backdropEl.style.opacity = isOpen ? 1 : 0;
99111

112+
this.currentTranslate = isOpen ? 0 : -100;
100113
this.dragState = DRAG_STATE_NONE;
101114
}
102115

103116
activeScreenChangedEvent({activeScreen}) {
104-
if (activeScreen === this.screenName) {
105-
this.$widget.addClass('show');
106-
} else {
107-
this.$widget.removeClass('show');
108-
}
117+
this.#setInitialState();
118+
this.#setSidebarOpen(activeScreen === this.screenName);
109119
}
110120

111121
}

0 commit comments

Comments
 (0)