diff --git a/src/gui/Base/HDrawerSwipeHandler.qml b/src/gui/Base/HDrawerSwipeHandler.qml new file mode 100644 index 00000000..37f738fe --- /dev/null +++ b/src/gui/Base/HDrawerSwipeHandler.qml @@ -0,0 +1,55 @@ +// Copyright Mirage authors & contributors +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 + +DragHandler { + id: root + + property HDrawer drawer + property bool swiped: false + property real minimumSwipeDistance: + Math.min(drawer.implicitWidth / 2, 100) * theme.uiScale + + readonly property HNumberAnimation hide: HNumberAnimation { + target: drawer + property: "position" + to: 0 + onStopped: root.closeRequest() + } + + readonly property HNumberAnimation cancel: HNumberAnimation { + target: drawer + property: "position" + to: 1 + } + + signal closeRequest() + + target: null + + enabled: + (drawer.collapse || drawer.forceCollapse) && + drawer.visible + + onTranslationChanged: { + if (hide.running || cancel.running) return + + drawer.position = + drawer.edge === Qt.LeftEdge ? 1 + translation.x / implicitWidth : + drawer.edge === Qt.RightEdge ? 1 - translation.x / implicitWidth : + drawer.edge === Qt.TopEdge ? 1 - translation.y / implicitHeight : + 1 + translation.y / implicitHeight + + const distance = Math.abs(translation[drawer.horizontal ? "x" : "y"]) + + if (distance > minimumSwipeDistance) swiped = true + } + + onSwipedChanged: if (swiped) hide.start() + + onActiveChanged: if (! active) { + if (! swiped) cancel.start() + swiped = false + } +} diff --git a/src/gui/MainPane/MainPane.qml b/src/gui/MainPane/MainPane.qml index 7e4b0de4..38fb0945 100644 --- a/src/gui/MainPane/MainPane.qml +++ b/src/gui/MainPane/MainPane.qml @@ -35,6 +35,11 @@ HDrawer { when: ! mainUI.accountsPresent } + HDrawerSwipeHandler { + drawer: mainPane + onCloseRequest: mainPane.toggleFocus() + } + HColumnLayout { anchors.fill: parent diff --git a/src/gui/Pages/Chat/RoomPane/RoomPane.qml b/src/gui/Pages/Chat/RoomPane/RoomPane.qml index 85d2748e..b097f8f2 100644 --- a/src/gui/Pages/Chat/RoomPane/RoomPane.qml +++ b/src/gui/Pages/Chat/RoomPane/RoomPane.qml @@ -96,7 +96,12 @@ MultiviewPane { onAboutToRecycle: roomPane.swipeView.currentIndex = 0 } - MemberView {} + MemberView { + HDrawerSwipeHandler { + drawer: roomPane + onCloseRequest: roomPane.toggleFocus() + } + } SettingsView { enabled: accountModel.presence !== "offline"