From e1c269f54ccd075dff8abd70b10d27ca46b4365e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Jan 2021 08:59:22 -0800 Subject: [PATCH] mobile/edit: fix broken screen repositioning In commit 622e5aab69 ("mobile/cleanup: remove more noisy debug output") I had good intentions, but missed the fact that in order to access the 'verbose' variable from QML I needed to use manager.verboseEnabled. The resulting syntax error went unnoticed and broke the screen repositioning when the keyboard opens on mobile devices. Worse, I called a non existing method to do the logging of debug information. And to top it all off, when I fixed the positioning algorithm in commit 765c4f9704 ("mobile/UI: fix the logic to keep input visible"), I forgot to fix the near identical logic for the TextArea for the notes. Fail on so many levels. Signed-off-by: Dirk Hohndel --- mobile-widgets/qml/DiveDetailsEdit.qml | 27 +++++++++++++++----------- mobile-widgets/qml/SsrfTextField.qml | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml index b6b28360e..abaa54abb 100644 --- a/mobile-widgets/qml/DiveDetailsEdit.qml +++ b/mobile-widgets/qml/DiveDetailsEdit.qml @@ -788,21 +788,26 @@ Item { selectByMouse: true wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere property bool firstTime: true - property int visibleTop: detailsEditFlickable.contentY - property int visibleBottom: visibleTop + detailsEditFlickable.height - 4 * Kirigami.Units.gridUnit onPressed: waitForKeyboard.start() onCursorRectangleChanged: { - ensureVisible(y + cursorRectangle.y) + ensureVisible() } - // ensure that the y coordinate is inside the visible part of the detailsEditFlickable (our flickable) - function ensureVisible(yDest) { - if (yDest > visibleBottom) - detailsEditFlickable.contentY += yDest - visibleBottom - if (yDest < visibleTop) - detailsEditFlickable.contentY -= visibleTop - yDest + function ensureVisible() { + // make sure there's enough space for the TextArea above the keyboard and action button + // and that it's not too far up, either + var flickable = detailsEditFlickable + var positionInFlickable = txtNotes.mapToItem(flickable.contentItem, 0, 0) + var taY = positionInFlickable.y + cursorRectangle.y + if (manager.verboseEnabled) + manager.appendTextToLog("position check: lower edge of view is " + + (0 + flickable.contentY + flickable.height) + + " and text area is at " + taY) + if (taY > flickable.contentY + flickable.height - 4 * Kirigami.Units.gridUnit) + flickable.contentY = Math.max(0, 4 * Kirigami.Units.gridUnit + taY - flickable.height) + while (taY < flickable.contentY) + flickable.contentY -= 2 * Kirigami.Units.gridUnit } - // give the OS enough time to actually resize the flickable Timer { id: waitForKeyboard @@ -816,7 +821,7 @@ Item { return } // make sure at least half the Notes field is visible - txtNotes.ensureVisible(txtNotes.y + txtNotes.cursorRectangle.y) + txtNotes.ensureVisible() } } } diff --git a/mobile-widgets/qml/SsrfTextField.qml b/mobile-widgets/qml/SsrfTextField.qml index 083235435..8f07f5ee1 100644 --- a/mobile-widgets/qml/SsrfTextField.qml +++ b/mobile-widgets/qml/SsrfTextField.qml @@ -65,8 +65,8 @@ Controls.TextField { // make sure there's enough space for the input field above the keyboard and action button (and that it's not too far up, either) var positionInFlickable = stf.mapToItem(flickable.contentItem, 0, 0) var stfY = positionInFlickable.y - if (verbose) - manager.appendTextToLogFile("position check: lower edge of view is " + (0 + flickable.contentY + flickable.height) + " and text field is at " + stfY) + if (manager.verboseEnabebled) + manager.appendTextToLog("position check: lower edge of view is " + (0 + flickable.contentY + flickable.height) + " and text field is at " + stfY) if (stfY + stf.height > flickable.contentY + flickable.height - 3 * Kirigami.Units.gridUnit || stfY < flickable.contentY) flickable.contentY = Math.max(0, 3 * Kirigami.Units.gridUnit + stfY + stf.height - flickable.height) }