lockscreen: Port from Flickable to SwipeArea

This commit is contained in:
Devin Lin 2023-09-29 22:57:58 -07:00
parent 911d41e5ce
commit f949ea7fdf
2 changed files with 107 additions and 143 deletions

View file

@ -5,8 +5,9 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell
Flickable { MobileShell.SwipeArea {
id: root id: root
property int position: 0 property int position: 0
@ -52,14 +53,6 @@ Flickable {
} }
} }
// we use flickable solely for capturing flicks, not positioning elements
contentWidth: width
contentHeight: height * 2
contentX: 0
contentY: startContentY
readonly property real startContentY: contentHeight / 2
property int oldPosition: position property int oldPosition: position
property bool movingUp: false property bool movingUp: false
@ -68,38 +61,15 @@ Flickable {
oldPosition = position; oldPosition = position;
} }
// update position from flickable movement onSwipeStarted: cancelAnimations();
property real oldContentY onSwipeEnded: {
onContentYChanged: {
position = Math.max(0, Math.min(keypadHeight, position + (contentY - oldContentY)));
oldContentY = contentY;
}
onMovementStarted: cancelAnimations();
onMovementEnded: {
if (!positionAnim.running) { if (!positionAnim.running) {
updateState(); updateState();
} }
resetPosition();
} }
onFlickStarted: root.cancelFlick() onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => {
onFlickEnded: resetPosition(); position = Math.max(0, Math.min(keypadHeight, position + deltaY));
onDraggingChanged: {
if (!dragging) {
resetPosition();
if (!positionAnim.running) {
root.updateState();
}
} else {
cancelAnimations();
}
}
function resetPosition() {
oldContentY = startContentY;
contentY = startContentY;
} }
} }

View file

@ -108,11 +108,6 @@ Item {
} }
} }
Item {
width: flickable.width
height: flickable.height
y: flickable.contentY // effectively anchored to the screen
LockScreenNarrowContent { LockScreenNarrowContent {
id: phoneComponent id: phoneComponent
@ -238,4 +233,3 @@ Item {
} }
} }
} }
}