Mobile: when switching to the details, reuse existing page

While pageStack.push() can handle pushing a page that's already there,
that creates an unfortunate sequence of currentItemChanged signal which
leads us to do the wrong thing with our map hack.

This commit changes things around to first look for the page in the page
stack and just switch to it, and only pushing the page as new if it
cannoot be found oon the page stack.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2019-10-07 16:23:28 -05:00
parent d8cc8732bd
commit b07a1cc8b6

View file

@ -36,6 +36,14 @@ Kirigami.ScrollablePage {
}
}
function pageIndex(pageToFind) {
for (var i = 0; i < pageStack.contentItem.contentChildren.length; i++) {
if (pageStack.contentItem.contentChildren[i] === pageToFind)
return i
}
return -1
}
Component {
id: diveDelegate
Kirigami.AbstractListItem {
@ -112,7 +120,12 @@ Kirigami.ScrollablePage {
if (detailsWindow.state === "view") {
diveListView.currentIndex = index
detailsWindow.showDiveIndex(index);
pageStack.push(detailsWindow);
// switch to detailsWindow (or push it if it's not in the stack)
var i = pageIndex(detailsWindow)
if (i === -1)
pageStack.push(detailsWindow)
else
pageStack.currentIndex = i
}
}