Reimplement swipe to exit sidepane via DragHandler

This commit is contained in:
miruka 2021-01-15 14:46:44 -04:00
parent 7029148c87
commit e4959f503c
3 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,55 @@
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
// 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
}
}

View File

@ -35,6 +35,11 @@ HDrawer {
when: ! mainUI.accountsPresent when: ! mainUI.accountsPresent
} }
HDrawerSwipeHandler {
drawer: mainPane
onCloseRequest: mainPane.toggleFocus()
}
HColumnLayout { HColumnLayout {
anchors.fill: parent anchors.fill: parent

View File

@ -96,7 +96,12 @@ MultiviewPane {
onAboutToRecycle: roomPane.swipeView.currentIndex = 0 onAboutToRecycle: roomPane.swipeView.currentIndex = 0
} }
MemberView {} MemberView {
HDrawerSwipeHandler {
drawer: roomPane
onCloseRequest: roomPane.toggleFocus()
}
}
SettingsView { SettingsView {
enabled: accountModel.presence !== "offline" enabled: accountModel.presence !== "offline"