homescreen: Add swipe down panel gesture

This commit is contained in:
Devin Lin 2021-10-28 21:54:52 -04:00
parent 0100d26024
commit 25e0f99f43
4 changed files with 72 additions and 22 deletions

View file

@ -8,6 +8,7 @@
import QtQuick 2.14
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import ".." as Launcher
@ -29,6 +30,7 @@ DragHandler {
}
property real __initialMainFlickableX
property real __oldTranslationY: 0
property int __scrollDirection: DragGestureHandler.None
onTranslationChanged: {
if (active) {
@ -50,7 +52,20 @@ DragHandler {
}
if (__scrollDirection !== DragGestureHandler.Left && __scrollDirection !== DragGestureHandler.Right) {
// if swipe up, scroll app drawer
root.appDrawer.flickable.contentY = Math.min(root.appDrawer.drawerTopMargin, Math.max(0, -translation.y));
if (translation.y < 0 && MobileShell.TopPanelControls.inSwipe) {
MobileShell.TopPanelControls.endSwipe();
}
// if swipe down, scroll top panel
if (translation.y > 0) {
if (!MobileShell.TopPanelControls.inSwipe) {
MobileShell.TopPanelControls.startSwipe();
}
MobileShell.TopPanelControls.requestRelativeScroll(translation.y - __oldTranslationY);
}
}
}
if (__scrollDirection !== DragGestureHandler.Vertical) {
@ -67,7 +82,10 @@ DragHandler {
mainFlickable.contentX = newContentX;
}
}
__oldTranslationY = translation.y;
}
onActiveChanged: {
if (active) {
__initialMainFlickableX = mainFlickable.contentX;
@ -75,6 +93,9 @@ DragHandler {
if (root.appDrawer) {
root.appDrawer.snapDrawerStatus();
}
if (MobileShell.TopPanelControls.inSwipe) {
MobileShell.TopPanelControls.endSwipe();
}
if (__scrollDirection === DragGestureHandler.Left && (__initialMainFlickableX - mainFlickable.contentX > PlasmaCore.Units.gridUnit * 5)) {
snapPrevPage();
} else if (__scrollDirection === DragGestureHandler.Right && (mainFlickable.contentX - __initialMainFlickableX > PlasmaCore.Units.gridUnit * 5)) {

View file

@ -11,5 +11,10 @@ pragma Singleton
QtObject {
id: root
signal startSwipe()
signal endSwipe()
signal requestRelativeScroll(real offsetY)
property bool inSwipe: false
property real panelHeight: PlasmaCore.Units.gridUnit // set and updated in panel containment
}

View file

@ -39,7 +39,7 @@ FocusScope {
//END functions
// implement API signals
//BEGIN API implementation
Connections {
target: MobileShell.HomeScreenControls
@ -60,6 +60,7 @@ FocusScope {
lastRequestedPosition = pos.y;
}
}
//END API implementation
property bool componentComplete: false
onWidthChanged: recalculateMaxFavoriteCount()

View file

@ -34,19 +34,34 @@ Item {
width: 480
height: PlasmaCore.Units.gridUnit
// set height binding to top panel API
Binding {
target: MobileShell.TopPanelControls
property: "panelHeight"
value: root.height
}
//BEGIN API implementation
// set height binding to top panel API
Binding {
target: MobileShell.TopPanelControls
property: "panelHeight"
value: root.height
}
Binding {
target: MobileShell.TopPanelControls
property: "inSwipe"
value: slidingPanel.userInteracting
}
Connections {
target: MobileShell.TopPanelControls
function onStartSwipe() {
swipeMouseArea.startSwipe(0);
}
function onEndSwipe() {
swipeMouseArea.endSwipe();
}
function onRequestRelativeScroll(offsetY) {
swipeMouseArea.updateOffset(offsetY);
}
}
//END API implementation
Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground
@ -196,31 +211,39 @@ Item {
showDropShadow: !showingApp
}
// initial swipe down
// initial swipe down gesture
MouseArea {
id: swipeMouseArea
z: 99
property int oldMouseY: 0
anchors.fill: parent
onPressed: {
function startSwipe(mouseX) {
slidingPanel.cancelAnimations();
slidingPanel.drawerX = Math.min(Math.max(0, mouse.x - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.contentItem.width)
slidingPanel.drawerX = Math.min(Math.max(0, mouseX - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.contentItem.width)
slidingPanel.userInteracting = true;
slidingPanel.flickable.contentY = slidingPanel.closedContentY;
oldMouseY = mouse.y;
slidingPanel.visible = true;
}
onPositionChanged: {
slidingPanel.updateOffset(mouse.y - oldMouseY);
function endSwipe() {
slidingPanel.userInteracting = false;
slidingPanel.updateState();
}
function updateOffset(offsetY) {
slidingPanel.updateOffset(offsetY);
}
anchors.fill: parent
onPressed: {
oldMouseY = mouse.y;
startSwipe(mouse.x);
}
onReleased: {
slidingPanel.userInteracting = false;
slidingPanel.updateState();
}
onCanceled: {
slidingPanel.userInteracting = false;
slidingPanel.updateState();
onReleased: endSwipe()
onCanceled: endSwipe()
onPositionChanged: {
updateOffset(mouse.y - oldMouseY);
oldMouseY = mouse.y;
}
}