Skip to content

Commit

Permalink
Hide keyboard when Launcher or Drawer are dragged
Browse files Browse the repository at this point in the history
The Launcher and Drawer do not respect the on-screen keyboard rectangle,
so about half of them are hidden when the Drawer's search field is
focused.

To fix this, unfocus the Drawer's search field when either of them move.

This does not remove focus when the user scrolls with the mouse wheel,
only when they click and drag or touch and drag.

Fixes ubports/ubuntu-touch#1238
Fixes ubports/ubuntu-touch#1245
  • Loading branch information
UniversalSuperBox committed Oct 18, 2019
1 parent 2c2664a commit 329a385
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qml/Launcher/Drawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ FocusScope {
searchField.focus = true;
}

function unFocusInput() {
searchField.focus = false;
}

Keys.onPressed: {
if (event.text.trim() !== "") {
focusInput();
Expand Down Expand Up @@ -279,6 +283,11 @@ FocusScope {
delegateWidth: root.delegateWidth
delegateHeight: units.gu(11)
delegate: drawerDelegateComponent
onDraggingVerticallyChanged: {
if (draggingVertically) {
unFocusInput();
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions qml/Launcher/DrawerGridView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FocusScope {
property alias model: gridView.model
property alias interactive: gridView.interactive
property alias currentIndex: gridView.currentIndex
property alias draggingVertically: gridView.draggingVertically

property alias header: gridView.header
property alias topMargin: gridView.topMargin
Expand Down
4 changes: 4 additions & 0 deletions qml/Launcher/Launcher.qml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ FocusScope {
root.focus = false;
}

onDraggingChanged: {
drawer.unFocusInput()
}

Behavior on x {
enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate;
NumberAnimation {
Expand Down
33 changes: 33 additions & 0 deletions tests/qmltests/Launcher/tst_Drawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,38 @@ StyledItem {
tryCompare(launcher, "state", "");
tryCompare(drawer, "draggingHorizontally", false);
}

function test_draggingAppListHidesKeyboard() {
// Ensures that dragging on the list of apps unfocuses the search
// field, hiding the keyboard
// Fix for https://github.com/ubports/ubuntu-touch/issues/1238
var drawer = dragDrawerIntoView();
var appList = findChild(drawer, "drawerAppList");
var searchField = drawer.searchTextField;

searchField.focus = true;

var startX = drawer.width / 2;
var startY = drawer.height / 2;
touchFlick(drawer, startX, startY, startX, startY+units.gu(1))

tryCompare(searchField, "focus", false);
}

function test_draggingLauncherHidesKeyboard() {
// Ensures that dragging on the Launcher unfocuses the search
// field, hiding the keyboard
// Fix for https://github.com/ubports/ubuntu-touch/issues/1245
var drawer = dragDrawerIntoView();
var searchField = drawer.searchTextField;

searchField.focus = true;

var startX = launcher.width / 2;
var startY = launcher.height / 2;
touchFlick(drawer, startX, startY, startX, startY+units.gu(1))

tryCompare(searchField, "focus", false);
}
}
}

0 comments on commit 329a385

Please sign in to comment.