on xenial help sign in
Basically skip animations if Showable not shown

There are instances where a Showable may be told to hide even if it is not currently shown. This happens quite a lot in use, since just saying 'hide()' is far better than 'if (shown) hide()'. However, this causes the Showable's hideAnimation to play, even if it's already hidden. This can cause an interesting problem when items' usability depends on whether their animations are playing, such as the PanelMenus disabling their DragHandles[1]. To fix this, immediately complete the hideAnimation (and showAnimation) when they are not needed. Doing this instead of not playing the animations at all corrects situations where shown was not set but the Showable is being shown somehow. This caused the panel tests to fail on timing issues (attempting to start a touch event while the Panel was still disabled), so I had to refactor one and add an ugly wait(). This also caused ShellWithPin's test_bfbOnLockedDevice to fail since the shell tried to open the Drawer then immediately call launcher.hide(). Previously the timing worked out somehow and hide() was called first. To fix this, remove the onSessionStarted() handler and move it to the Greeter's onActiveChanged handler instead. [1] https://github.com/ubports/unity8/pull/205

commit6d933554a0af25fc654f42ed5782a3e8d37b1204 authorDalton Durst <dalton@ubports.com> dateFri 27 Dec 2019, 14:10 (7 years ago) parentd42c110
3 files changed+43−28
qml/Components/Showable.qml+3−2 qml/Shell.qml+4−5 tests/qmltests/Panel/tst_PanelMenu.qml+36−21
qml/Components/Showable.qml+3−2
@@ -1,5 +1,6 @@
11/*
22 * Copyright (C) 2013 Canonical, Ltd.
3+ * Copyright (C) 2019 UBports Foundation
34 *
45 * This program is free software; you can redistribute it and/or modify
56 * it under the terms of the GNU General Public License as published by
@@ -88,7 +89,7 @@ Item {
8889 if (!showAnimation.running) {
8990 showAnimation.restart()
9091 }
91− if (__skipShowAnimation) {
92+ if (__skipShowAnimation || shown) {
9293 showAnimation.complete();
9394 }
9495 } else {
@@ -121,7 +122,7 @@ Item {
121122 if (!hideAnimation.running) {
122123 hideAnimation.restart()
123124 }
124− if (__skipHideAnimation) {
125+ if (__skipHideAnimation || !shown) {
125126 hideAnimation.complete();
126127 }
127128 } else {
qml/Shell.qml+4−5
@@ -1,5 +1,6 @@
11/*
22 * Copyright (C) 2013-2016 Canonical, Ltd.
3+ * Copyright (C) 2019 UBports Foundation
34 *
45 * This program is free software; you can redistribute it and/or modify
56 * it under the terms of the GNU General Public License as published by
@@ -405,7 +406,9 @@ StyledItem {
405406 }
406407 // Show the launcher when there are no running apps
407408 else if (topLevelSurfaceList.count < 1) {
408− launcher.switchToNextState("visible")
409+ launcher.switchToNextState("visible");
410+ } else {
411+ launcher.hide();
409412 }
410413 }
411414 }
@@ -431,10 +434,6 @@ StyledItem {
431434 // left-edge drag
432435 dragHandleLeftMargin: launcher.available ? launcher.dragAreaWidth + 1 : 0
433436
434− onSessionStarted: {
435− launcher.hide();
436− }
437−
438437 onTease: {
439438 if (!tutorial.running) {
440439 launcher.tease();
tests/qmltests/Panel/tst_PanelMenu.qml+36−21
@@ -1,5 +1,6 @@
11/*
22 * Copyright 2013-2016 Canonical Ltd.
3+ * Copyright 2019 UBports Foundation
34 *
45 * This program is free software; you can redistribute it and/or modify
56 * it under the terms of the GNU General Public License as published by
@@ -137,16 +138,18 @@ PanelTest {
137138 when: windowShown
138139
139140 function init() {
140− indicatorsMenu.hide();
141− tryCompare(indicatorsMenu.hideAnimation, "running", false);
142− compare(indicatorsMenu.state, "initial");
143−
144141 indicatorsMenu.verticalVelocityThreshold = 0.5
142+ tryCompare(indicatorsMenu.hideAnimation, "running", false);
143+ tryCompare(indicatorsMenu, "state", "initial");
144+ wait(100);
145145 }
146146
147147 function cleanup() {
148+ touchRelease(root);
148149 clickThroughSpy.clear();
149150 showTappedSpy.clear();
151+ indicatorsMenu.hideAnimation.complete();
152+ indicatorsMenu.hideNow();
150153 }
151154
152155 function get_indicator_item(index) {
@@ -226,33 +229,45 @@ PanelTest {
226229 touchRelease(indicatorsMenu, mappedPosition.x, indicatorsMenu.minimizedPanelHeight / 2);
227230 }
228231
232+ function test_swipeForCurrentItem_data() {
233+ return [
234+ {item: 0},
235+ {item: 1},
236+ {item: 2},
237+ {item: 3},
238+ {item: 4},
239+ {item: 5},
240+ {item: 6},
241+ {item: 7},
242+ {item: 8},
243+ ]
244+ }
245+
229246 // tests swiping on an indicator item activates the correct item.
230− function test_swipeForCurrentItem()
247+ function test_swipeForCurrentItem(data)
231248 {
232249 var panelItemRow = findChild(indicatorsMenu, "panelItemRow");
233250 verify(panelItemRow !== null);
234251
235− for (var i = 0; i < root.originalModelData.length; i++) {
236− var indicatorItem = get_indicator_item(i);
252+ var indicatorItem = get_indicator_item(data.item);
237253
238− var mappedPosition = indicatorsMenu.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
254+ var mappedPosition = indicatorsMenu.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
239255
240− touchFlick(indicatorsMenu,
241− mappedPosition.x, mappedPosition.y,
242− mappedPosition.x, indicatorsMenu.openedHeight / 2,
243− true /* beginTouch */, false /* endTouch */);
256+ touchFlick(indicatorsMenu,
257+ mappedPosition.x, mappedPosition.y,
258+ mappedPosition.x, indicatorsMenu.openedHeight / 2,
259+ true /* beginTouch */, false /* endTouch */);
244260
245− tryCompare(panelItemRow, "currentItem", indicatorItem, undefined /*timeout, default */,
246− "Incorrect item activated at position " + i);
261+ tryCompare(panelItemRow, "currentItem", indicatorItem, undefined /*timeout, default */,
262+ "Incorrect item activated at position " + data.item);
247263
248− touchFlick(panelItemRow,
249− mappedPosition.x, indicatorsMenu.openedHeight / 2,
250− mappedPosition.x, mappedPosition.y,
251− false /* beginTouch */, true /* endTouch */);
264+ touchFlick(panelItemRow,
265+ mappedPosition.x, indicatorsMenu.openedHeight / 2,
266+ mappedPosition.x, mappedPosition.y,
267+ false /* beginTouch */, true /* endTouch */);
252268
253− // wait until fully closed
254− tryCompare(indicatorsMenu, "fullyClosed", true);
255− }
269+ // wait until fully closed
270+ tryCompare(indicatorsMenu, "fullyClosed", true);
256271 }
257272
258273 // Test the vertical velocity check when flicking the indicators open at an angle.