on xenial help sign in
properly reset the drawer state when cancelling a horizontal drag (LP: #1669536)

Approved by: Lukáš Tinkl, Unity8 CI Bot

commitfe7f3cf6281360890881f0946d4edb6acd808b83 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 21 Mar 2017, 10:54 (10 years ago) parent89f8610ff6e4b5
3 files changed+31−11
qml/Launcher/Drawer.qml+4−1 qml/Launcher/Launcher.qml+9−10 tests/qmltests/Launcher/tst_Drawer.qml+18
qml/Launcher/Drawer.qml+4−1
@@ -212,13 +212,16 @@ FocusScope {
212212 root.dragDistance += diff;
213213 oldX = mouseX
214214 }
215− onReleased: {
215+ onReleased: reset();
216+ onCanceled: reset();
217+ function reset() {
216218 if (root.draggingHorizontally) {
217219 root.draggingHorizontally = false;
218220 parent.interactive = true;
219221 }
220222 reactivateTimer.start();
221223 }
224+
222225 Timer {
223226 id: reactivateTimer
224227 interval: 0
qml/Launcher/Launcher.qml+9−10
@@ -120,7 +120,14 @@ FocusScope {
120120 }
121121 return;
122122 }
123− switchToNextState("")
123+ if (root.lockedVisible) {
124+ // Due to binding updates when switching between modes
125+ // it could happen that our request to show will be overwritten
126+ // with a hide request. Rewrite it when we know hiding is not allowed.
127+ switchToNextState("visible")
128+ } else {
129+ switchToNextState("")
130+ }
124131 }
125132
126133 function fadeOut() {
@@ -258,13 +265,6 @@ FocusScope {
258265 interval: 1
259266 property string nextState: ""
260267 onTriggered: {
261− if (root.lockedVisible && nextState == "") {
262− // Due to binding updates when switching between modes
263− // it could happen that our request to show will be overwritten
264− // with a hide request. Rewrite it when we know hiding is not allowed.
265− nextState = "visible"
266− }
267−
268268 // switching to an intermediate state here to make sure all the
269269 // values are restored, even if we were already in the target state
270270 root.state = "tmp"
@@ -383,8 +383,7 @@ FocusScope {
383383 }
384384
385385 Keys.onEscapePressed: {
386− switchToNextState("");
387− root.focus = false;
386+ root.hide()
388387 }
389388
390389 onDragDistanceChanged: {
tests/qmltests/Launcher/tst_Drawer.qml+18
@@ -328,5 +328,23 @@ StyledItem {
328328
329329 tryCompare(launcher, "state", "visibleTemporary");
330330 }
331+
332+ function test_closeWhileDragging() {
333+ launcher.openDrawer(true);
334+ waitForRendering(launcher);
335+ waitUntilTransitionsEnd(launcher);
336+
337+ var drawer = findChild(launcher, "drawer");
338+ tryCompare(drawer.anchors, "rightMargin", -drawer.width);
339+
340+ mousePress(drawer, drawer.width / 2, drawer.height / 2);
341+ mouseMove(drawer, drawer.width / 4, drawer.height / 2);
342+ tryCompare(drawer, "draggingHorizontally", true);
343+
344+ keyPress(Qt.Key_Escape);
345+
346+ tryCompare(launcher, "state", "");
347+ tryCompare(drawer, "draggingHorizontally", false);
348+ }
331349 }
332350}