From 911d41e5ce17ad9e2c99bf3c9690ec61d98c65ac Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 29 Sep 2023 22:57:24 -0700 Subject: [PATCH] actiondrawer: Port from Flickable to SwipeArea --- .../qml/actiondrawer/ActionDrawer.qml | 63 ++++--------------- .../actiondrawer/ActionDrawerOpenSurface.qml | 20 +++--- 2 files changed, 20 insertions(+), 63 deletions(-) diff --git a/components/mobileshell/qml/actiondrawer/ActionDrawer.qml b/components/mobileshell/qml/actiondrawer/ActionDrawer.qml index 5f820e90..14033175 100644 --- a/components/mobileshell/qml/actiondrawer/ActionDrawer.qml +++ b/components/mobileshell/qml/actiondrawer/ActionDrawer.qml @@ -113,9 +113,9 @@ Item { signal runPendingNotificationAction() onOpenedChanged: { - if (opened) flickable.focus = true; + if (opened) swipeArea.focus = true; } - + property real oldOffset onOffsetChanged: { if (offset < 0) { @@ -129,7 +129,7 @@ Item { oldOffset = offset; // close panel immediately after panel is not shown, and the flickable is not being dragged - if (opened && root.offset <= 0 && !flickable.dragging && !closeAnim.running && !openAnim.running) { + if (opened && root.offset <= 0 && !swipeArea.moving && !closeAnim.running && !openAnim.running) { root.updateState(); focus = false; } @@ -229,68 +229,29 @@ Item { onFinished: root.opened = true; } - Components.Flickable { - id: flickable + MobileShell.SwipeArea { + id: swipeArea anchors.fill: parent - - contentWidth: root.width - contentHeight: root.height + 999999 - contentY: contentHeight / 2 - - // if the recent root.offset change was due to this flickable - property bool offsetChangedDueToContentY: false - Connections { - target: root - function onOffsetChanged() { - if (!flickable.offsetChangedDueToContentY) { - // ensure the flickable's contentY is not moving when other sources change root.offset - flickable.cancelFlick(); - } - flickable.offsetChangedDueToContentY = false; - } - } - - property real oldContentY - onContentYChanged: { - offsetChangedDueToContentY = true; - root.offset += oldContentY - contentY; - oldContentY = contentY; - } - - onMovementStarted: { + + onSwipeStarted: { root.cancelAnimations(); root.dragging = true; } - onFlickStarted: root.dragging = true; - onMovementEnded: { + onSwipeEnded: { root.dragging = false; root.updateState(); } - onFlickEnded: { - root.dragging = true; - root.updateState(); + onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => { + root.offset += deltaY; } - - onDraggingChanged: { - if (!dragging) { - root.dragging = false; - flickable.cancelFlick(); - root.updateState(); - } - } - - // the flickable is only used to measure drag changes, we implement our own UI component movements - // the root element is not affected by contentY changes (it's effectively anchored to the flickable) + Loader { id: contentContainerLoader + anchors.fill: parent property real minimizedQuickSettingsOffset: item ? item.minimizedQuickSettingsOffset : 0 property real maximizedQuickSettingsOffset: item ? item.maximizedQuickSettingsOffset : 0 - y: flickable.contentY - width: root.width - height: root.height - asynchronous: true sourceComponent: root.mode == ActionDrawer.Portrait ? portraitContentContainer : landscapeContentContainer } diff --git a/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml b/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml index a0871ad7..f44abc0f 100644 --- a/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml +++ b/components/mobileshell/qml/actiondrawer/ActionDrawerOpenSurface.qml @@ -7,11 +7,12 @@ import QtQuick 2.15 import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings +import org.kde.plasma.private.mobileshell as MobileShell /** * Component that triggers the opening and closing of an ActionDrawer when dragged on with touch or mouse. */ -MouseArea { +MobileShell.SwipeArea { id: root required property ActionDrawer actionDrawer @@ -43,22 +44,17 @@ MouseArea { } anchors.fill: parent - onPressed: mouse => { - oldMouseY = mouse.y; - + + onSwipeStarted: (point) => { // if the user swiped from the top left, otherwise it's from the top right - if (mouse.x < root.width / 2) { + if (point.x < root.width / 2) { actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopLeftMode == ShellSettings.Settings.Pinned; } else { actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopRightMode == ShellSettings.Settings.Pinned; } - + startSwipe(); } - onReleased: endSwipe() - onCanceled: endSwipe() - onPositionChanged: mouse => { - updateOffset(mouse.y - oldMouseY); - oldMouseY = mouse.y; - } + onSwipeEnded: endSwipe() + onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => updateOffset(deltaY); }