Ask / Submit
0

Cover action spawns another instance of page [answered]

asked 2017-09-10 20:19:17 +0300

Edz gravatar image

I have added a search icon to my application's cover, allowing the user to go directly to the search page.

If I navigate away from the newly spawned search page and tap on the cover's search icon again, another instance of search page is stacked on the first one, this is continually repeatable and not desired.

How do I prevent the same page from spawning more than once from the cover action?

The current CoverPage.qml resides in pages directory and is as follows;

import QtQuick 2.0
import Sailfish.Silica 1.0

CoverBackground {
    Image {
        id: logo
        source: "../images/harbour-nationalrail.png"
        anchors {
            top: parent.top
            topMargin: Theme.paddingLarge
            horizontalCenter: parent.horizontalCenter
        }
        Label {
            text: "Live\nDeparture\nBoards"
            width: parent.width
            wrapMode: Text.WordWrap
            horizontalAlignment: Text.AlignHCenter
            anchors {
                top: logo.bottom
                topMargin: Theme.paddingLarge
            }
        }
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: {
                pageStack.push('Search.qml', {}, PageStackAction.Immediate)
                window.activate()
            }
        }
    }
}
edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by Edz
close date 2017-09-11 03:52:53.920957

Comments

I don't know... maybe just check if current page is search page and skip pushing it to page stack and only activate window?

coderus ( 2017-09-10 22:25:18 +0300 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-09-11 03:52:33 +0300

Edz gravatar image

updated 2017-09-11 12:15:50 +0300

I've answered my own question, the code now is as follows;

import QtQuick 2.0
import Sailfish.Silica 1.0

CoverBackground {
    CoverPlaceholder {
        text: "Live Departure Boards"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: {
                pageStack.navigateBack(PageStackAction.Immediate)
                pageStack.push('Search.qml')
                pageStack.navigateForward(PageStackAction.Immediate)
                activate()
            }
        }
    }

This may not be the best way to do it, but it works! :)

Regards,

edit flag offensive delete publish link more

Question tools

Follow
1 follower

Stats

Asked: 2017-09-10 20:19:17 +0300

Seen: 100 times

Last updated: Sep 11