on xenial help sign in
Refactor the Drawer for easier testing

Move most of the behavior for the Drawer out of Launcher and into Drawer, using signals to acheive anything that Drawer can't do by itself

commitc1712df8f7fd0b3c5aad210811cc52907dc2ba5d authorDalton Durst <dalton@ubports.com> dateMon 13 May 2019, 19:08 (7 years ago) parentbbea6bd
2 files changed+76−52
qml/Launcher/Drawer.qml+71 qml/Launcher/Launcher.qml+5−52
qml/Launcher/Drawer.qml+71
@@ -31,12 +31,82 @@ FocusScope {
3131 readonly property bool moving: appList && appList.moving
3232 readonly property Item searchTextField: searchField
3333 readonly property real delegateWidth: units.gu(10)
34+ visible: x > -width
35+ property var fullyOpen: x === 0
36+ property var fullyClosed: x === -width
3437
3538 signal applicationSelected(string appId)
3639
40+ // Request that the Drawer is opened fully, if it was partially closed then
41+ // brought back
42+ signal open();
43+
44+ // Request that the Drawer (and maybe its parent) is hidden, normally if
45+ // the Drawer has been dragged away.
46+ signal hide();
47+
48+ property bool allowSlidingAnimation: false
3749 property bool draggingHorizontally: false
3850 property int dragDistance: 0
3951
52+ property var hadFocus: false
53+ property var oldSelectionStart: null
54+ property var oldSelectionEnd: null
55+
56+ anchors {
57+ onRightMarginChanged: {
58+ if (fullyOpen && hadFocus) {
59+ // See onDraggingHorizontallyChanged below
60+ searchField.focus = hadFocus;
61+ searchField.select(oldSelectionStart, oldSelectionEnd);
62+ return;
63+ } else if (fullyClosed || fullyOpen) {
64+ searchField.text = "";
65+ resetOldFocus();
66+ }
67+ }
68+ }
69+
70+ Behavior on anchors.rightMargin {
71+ enabled: allowSlidingAnimation && !draggingHorizontally
72+ NumberAnimation {
73+ duration: 300
74+ easing.type: Easing.OutCubic
75+ }
76+ }
77+
78+ onDraggingHorizontallyChanged: {
79+ if (draggingHorizontally) {
80+ // Remove (and put back using anchors.onRightMarginChanged) the
81+ // focus for the searchfield in order to hide the copy/paste
82+ // popover when we move the drawer
83+ hadFocus = searchField.focus;
84+ oldSelectionStart = searchField.selectionStart;
85+ oldSelectionEnd = searchField.selectionEnd;
86+ searchField.focus = false;
87+ } else {
88+ if (x < -units.gu(10)) {
89+ hide();
90+ } else {
91+ requestOpen();
92+ }
93+ }
94+ }
95+
96+ Keys.onEscapePressed: {
97+ root.hide()
98+ }
99+
100+ onDragDistanceChanged: {
101+ anchors.rightMargin = Math.max(-drawer.width, anchors.rightMargin + dragDistance);
102+ }
103+
104+ function resetOldFocus() {
105+ hadFocus = false;
106+ oldSelectionStart = null;
107+ oldSelectionEnd = null;
108+ }
109+
40110 function focusInput() {
41111 searchField.selectAll();
42112 searchField.focus = true;
@@ -96,6 +166,7 @@ FocusScope {
96166
97167 MouseArea {
98168 id: drawerHandle
169+ objectName: "drawerHandle"
99170 anchors {
100171 right: parent.right
101172 top: parent.top
qml/Launcher/Launcher.qml+5−52
@@ -352,34 +352,10 @@ FocusScope {
352352 topMargin: root.inverted ? root.topPanelHeight : 0
353353 bottom: parent.bottom
354354 right: parent.left
355− onRightMarginChanged: {
356− if (fullyOpen && hadFocus) {
357− // See drawer.onDraggingHorizontallyChanged below
358− drawer.searchTextField.focus = hadFocus;
359− drawer.searchTextField.select(oldSelectionStart, oldSelectionEnd);
360− } else if (fullyClosed) {
361− drawer.searchTextField.text = "";
362− }
363− resetOldFocus();
364− }
365355 }
366356 width: Math.min(root.width, units.gu(81))
367357 panelWidth: panel.width
368− visible: x > -width
369− property var fullyOpen: x === 0
370− property var fullyClosed: x === -width
371−
372− property var hadFocus: false
373− property var oldSelectionStart: null
374− property var oldSelectionEnd: null
375−
376− Behavior on anchors.rightMargin {
377− enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate && !drawer.draggingHorizontally
378− NumberAnimation {
379− duration: 300
380− easing.type: Easing.OutCubic
381− }
382− }
358+ allowSlidingAnimation: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate
383359
384360 onApplicationSelected: {
385361 root.hide();
@@ -387,35 +363,12 @@ FocusScope {
387363 root.focus = false;
388364 }
389365
390− function resetOldFocus() {
391− hadFocus = false;
392− oldSelectionStart = null;
393− oldSelectionEnd = null;
394− }
395−
396− Keys.onEscapePressed: {
397− root.hide()
366+ onHide: {
367+ root.hide();
398368 }
399369
400− onDragDistanceChanged: {
401− anchors.rightMargin = Math.max(-drawer.width, anchors.rightMargin + dragDistance);
402− }
403− onDraggingHorizontallyChanged: {
404− if (draggingHorizontally) {
405− // Remove (and put back using anchors.onRightMarginChanged) the
406− // focus for the searchfield in order to hide the copy/paste
407− // popover when we move the drawer
408− hadFocus = drawer.searchTextField.focus;
409− oldSelectionStart = drawer.searchTextField.selectionStart;
410− oldSelectionEnd = drawer.searchTextField.selectionEnd;
411− drawer.searchTextField.focus = false;
412− } else {
413− if (drawer.x < -units.gu(10)) {
414− root.hide();
415− } else {
416− root.toggleDrawer(false, true);
417− }
418− }
370+ onOpen: {
371+ root.toggleDrawer(false, true);
419372 }
420373 }
421374