on xenial help sign in
allow cancelling the revealing of the drawer by changing direction of the swipe
commit45cb1ad097b97b866a4f9b1d972758180414260f authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parentfbcea9b
2 files changed+45−4
qml/Launcher/Launcher.qml+26−4 tests/qmltests/Launcher/tst_Drawer.qml+19
qml/Launcher/Launcher.qml+26−4
@@ -496,12 +496,33 @@ FocusScope {
496496
497497 function easeInOutCubic(t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 }
498498
499+ property var lastDragPoints: []
500+
501+ function dragDirection() {
502+ if (lastDragPoints.length < 5) {
503+ return "unknown";
504+ }
505+
506+ var toRight = true;
507+ var toLeft = true;
508+ for (var i = lastDragPoints.length - 5; i < lastDragPoints.length; i++) {
509+ if (toRight && lastDragPoints[i] < lastDragPoints[i-1]) {
510+ toRight = false;
511+ }
512+ if (toLeft && lastDragPoints[i] > lastDragPoints[i-1]) {
513+ toLeft = false;
514+ }
515+ }
516+ return toRight ? "right" : toLeft ? "left" : "unknown";
517+ }
518+
499519 onDistanceChanged: {
500520 if (dragging && launcher.state != "visible" && launcher.state != "drawer") {
501521 panel.x = -panel.width + Math.min(Math.max(0, distance), panel.width);
502522 }
503523
504524 if (root.drawerEnabled && dragging && launcher.state != "drawer") {
525+ lastDragPoints.push(distance)
505526 var drawerHintDistance = panel.width + units.gu(1)
506527 if (distance < drawerHintDistance) {
507528 drawer.anchors.rightMargin = -Math.min(Math.max(0, distance), drawer.width);
@@ -517,17 +538,18 @@ FocusScope {
517538 onDraggingChanged: {
518539 if (!dragging) {
519540 if (distance > panel.width / 2) {
520− if (root.drawerEnabled && distance > panel.width * 3) {
521− root.switchToNextState("drawer")
541+ if (root.drawerEnabled && distance > panel.width * 3 && dragDirection() !== "left") {
542+ root.switchToNextState("drawer");
522543 root.focus = true;
523544 } else {
524− root.switchToNextState("visible")
545+ root.switchToNextState("visible");
525546 }
526547 } else if (root.state === "") {
527548 // didn't drag far enough. rollback
528− root.switchToNextState("")
549+ root.switchToNextState("");
529550 }
530551 }
552+ lastDragPoints = [];
531553 }
532554 }
533555
tests/qmltests/Launcher/tst_Drawer.qml+19
@@ -241,5 +241,24 @@ StyledItem {
241241
242242 compare(launcher.lastSelectedApplication, "camera-app");
243243 }
244+
245+ function test_dragDirectionOnLeftEdgeDrag_data() {
246+ return [
247+ { tag: "reveal", direction: "right", endState: "drawer" },
248+ { tag: "cancel", direction: "left", endState: "visible" },
249+ ]
250+ }
251+
252+ function test_dragDirectionOnLeftEdgeDrag(data) {
253+ var startX = launcher.dragAreaWidth/2;
254+ var startY = launcher.height/2;
255+ var stopX = startX + units.gu(35);
256+ var endX = stopX + (units.gu(4) * (data.direction === "left" ? -1 : 1))
257+
258+ touchFlick(launcher, startX, startY, stopX, startY, true, false);
259+ touchFlick(launcher, stopX, startY, endX, startY, false, true);
260+
261+ tryCompare(launcher, "state", data.endState)
262+ }
244263 }
245264}