From 11d39cd942f85acad8892ef7eae2edd0b4438d00 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 31 Oct 2023 12:12:10 +0100 Subject: [PATCH] qml: fix keyboard exclusion zone turns out that Qt.inputMethod.keyboardRectangle.height is not suitable for calculating the exact keyboard dimensions in Qt coordinates. Instead, use Qt.inputMethod.keyboardRectangle.y transformed to Qt coordinates using Screen.devicePixelRatio Note: Qt.inputMethod.keyboardRectangle stop being updated after exiting FLAG_SECURE state (e.g. in seed or master key entry pages) --- .../gui/qml/components/controls/ElDialog.qml | 2 +- electrum/gui/qml/components/main.qml | 48 ++++++++++--------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/electrum/gui/qml/components/controls/ElDialog.qml b/electrum/gui/qml/components/controls/ElDialog.qml index f4e74e058..61e8ad5e6 100644 --- a/electrum/gui/qml/components/controls/ElDialog.qml +++ b/electrum/gui/qml/components/controls/ElDialog.qml @@ -35,7 +35,7 @@ Dialog { reject() } - parent: resizeWithKeyboard ? Overlay.overlay.children[0] : Overlay.overlay + parent: resizeWithKeyboard ? app.keyboardFreeZone : Overlay.overlay modal: true Overlay.modal: Rectangle { color: "#aa000000" diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml index eb93ce13b..5a6c14a7c 100644 --- a/electrum/gui/qml/components/main.qml +++ b/electrum/gui/qml/components/main.qml @@ -32,6 +32,7 @@ ApplicationWindow Constants { id: appconstants } property alias stack: mainStackView + property alias keyboardFreeZone: _keyboardFreeZone property variant activeDialogs: [] @@ -210,15 +211,13 @@ ApplicationWindow } // hack to force relayout of toolbar - // since qt6 watchOnlyIndicator.visible doesn't trigger relayout(?) + // since qt6 LightningNetworkStatusIndicator.visible doesn't trigger relayout(?) Item { Layout.preferredHeight: 1 Layout.topMargin: -1 - Layout.preferredWidth: watchOnlyIndicator.visible + Layout.preferredWidth: lnnsi.visible ? 1 - : lnnsi.visible - ? 2 - : 3 + : 2 } } } @@ -226,7 +225,7 @@ ApplicationWindow StackView { id: mainStackView width: parent.width - height: keyboardFreeZone.height - header.height + height: _keyboardFreeZone.height - header.height initialItem: Component { WalletMainView {} } @@ -270,7 +269,7 @@ ApplicationWindow } Item { - id: keyboardFreeZone + id: _keyboardFreeZone // Item as first child in Overlay that adjusts its size to the available // screen space minus the virtual keyboard (e.g. to center dialogs in) // see also ElDialog.resizeWithKeyboard property @@ -278,39 +277,42 @@ ApplicationWindow width: parent.width height: parent.height - states: State { - name: "visible" - when: Qt.inputMethod.visible - PropertyChanges { - target: keyboardFreeZone - height: keyboardFreeZone.parent.height - Qt.inputMethod.keyboardRectangle.height / Screen.devicePixelRatio + states: [ + State { + name: 'visible' + when: Qt.inputMethod.keyboardRectangle.y + PropertyChanges { + target: _keyboardFreeZone + height: _keyboardFreeZone.parent.height - (Screen.desktopAvailableHeight - (Qt.inputMethod.keyboardRectangle.y/Screen.devicePixelRatio)) + } } - } + ] + transitions: [ Transition { from: '' to: 'visible' - ParallelAnimation { - NumberAnimation { - properties: "height" - duration: 250 - easing.type: Easing.OutQuad - } + NumberAnimation { + properties: 'height' + duration: 100 + easing.type: Easing.OutQuad } }, Transition { from: 'visible' to: '' - ParallelAnimation { + SequentialAnimation { + PauseAnimation { + duration: 200 + } NumberAnimation { - properties: "height" + properties: 'height' duration: 50 easing.type: Easing.OutQuad } } } ] - } property alias newWalletWizard: _newWalletWizard