Commit e5536846 authored by Karel Slaný's avatar Karel Slaný

Fixed back button navigation on Android.

parent 063fbc96
......@@ -94,6 +94,9 @@ ApplicationWindow {
}
}
/* Exposes nested stack to code outside the page component. */
property var nestedStack: null
StackView { // Page area.
id: mainStack
anchors.fill: parent
......@@ -107,6 +110,10 @@ ApplicationWindow {
objectName: "appArea"
anchors.fill: parent
StackView.onActivated: {
mainStack.forceActiveFocus()
}
Rectangle { /* Application page stack. */
id: mainPage
anchors.fill: parent
......@@ -117,6 +124,10 @@ ApplicationWindow {
anchors.fill: parent
visible: true
initialItem: PageAccountList {}
Component.onCompleted: {
nestedStack = pageView
}
}
}
Rectangle {
......@@ -301,20 +312,32 @@ ApplicationWindow {
}
}
/* Android back button. */
focus: true
Keys.onReleased: {
function navigateBack(mainStack, nestedStack, event) {
if (event.key === Qt.Key_Back) {
event.accepted = true
if (pageView.depth > 1) {
event.accepted = true
pageView.pop(StackView.Immediate)
if (nestedStack == null) {
return
}
if (mainStack.currentItem.objectName == "lockScreen") {
console.log("Ignoring back button on lock screen.")
} else if (mainStack.depth > 1) {
mainStack.pop(StackView.Immediate)
} else if (nestedStack.depth > 1) {
nestedStack.pop(StackView.Immediate)
} else {
event.accepted = false
Qt.quit()
}
}
}
/* Android back button. */
focus: true
Keys.onReleased: {
navigateBack(mainStack, nestedStack, event)
}
}
Text {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment