Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany
Accepted Solution

Get default back button on separate sheet

I have my preferences in a separate Sheet with its own NavigationPane.

(as the application menu should not be available there)

 

I would like to have the same "back" action as a normal page though.

When i define a back action in actions i get it placed in the middle of the action bar, which is not looking good.

 

How can i get it to look like the default "back"?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: Get default back button on separate sheet

I'm not sure if you can do exactly what you're asking without recreating the whole Action Bar with the Back button (which for various reasons would be crazy, not the least of which is you likely wouldn't get the automatic internationalization support).

If your reason to use a Sheet is merely to avoid the menu being available, I suggest just using a regular Page or Dialog and tracking whether it is visible or not. When it's visible, use Application.menuEnabled to disable the top-swipe menu: https://developer.blackberry.com/cascades/reference/bb__cascades__application.html#menuenabled

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
bcs925
Posts: 258
Registered: ‎07-13-2012
My Carrier: T-Mobile

Re: Get default back button on separate sheet

Just like Peter said, I don't think what you are trying to do is possible unless you push to a new page then disable the menu on that new page.  What I've done to get around that and still use Sheet (from a UX standpoint) is have a "close" action rather than a "back" action. In my scenario I have an "X" for an image rather than a "<"

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Please use plain text.
Regular Contributor
Megha_9_dec
Posts: 56
Registered: ‎08-21-2012
My Carrier: RIM

Re: Get default back button on separate sheet

[ Edited ]

Hi Simon,

 

dismiss ActionItem inside TitleBar is what you're looking for.

Here I'm providing you a sample :

 

Sheet{
Page{ signal done() titleBar: TitleBar { dismissAction: ActionItem { title: "Back" onTriggered: { done()
} } }
Container{ } }
}

 

Best Regards,

Megha Patel

Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Get default back button on separate sheet

i'll check both approaches when i am back in the office, but i guess Application.menuEnabled provides a simple solution, at least for my current issue.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Get default back button on separate sheet

regarding https://developer.blackberry.com/cascades/reference/bb__cascades__application.html#menuenabled
could you give me a hint how to use it?
Do i use onCreationComplete and onDestroyed to enable/disable the menu? And how do i access the menus enabled property? Or would i use an own menu on the preferences page (and disable that one)?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: Get default back button on separate sheet

You can access it through the global Application object that's exposed to the QML, so Application.menuEnabled = false should work.

You can't use (as far as I know) onDestroyed in the QML, so though you could use onCreationCompleted if you do it only once, or if you create new instances of the component each time you open the Page, I would instead watch the topChanged signal with an onTopChanged handler in the NavigationPane, monitoring to see which Page was now on top and enabling/disabling the menu based on that.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Get default back button on separate sheet

I have added this code in my NavigationPane:

 

 onTopChanged: {
     console.debug("top changed to id: "+page.id);
}

 

but get only this:

Debug: top changed to id: undefined

 

How do i identify the top page correctly?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: Get default back button on separate sheet

There may be more than one way, but this is working for me in a case where I'm dynamically creating the secondary Page on which I want the menu disabled:

// in main.qml
NavigationPane {
    id: root

    property variant chart_page
    ...

    onSomeEvent: {
        if (!chart_page)
            chart_page = chartDefinition.createObject();
        root.push(chart_page);
    }

    ...
    onTopChanged: {
        Application.menuEnabled = Boolean(page != chart_page);
        // note: Boolean() not really necessary, just here to 
        // make the code clearer
    }

}

 

 


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: Get default back button on separate sheet

By the way, I think the "id" approach isn't working for you because "id" is special... not a regular property. I think it's used solely in defining the QML and gives you a name by which you can reference the page, but it does not show up as a property. That's why it's also not accessible from C++: you need to use objectName in that case, and that would actually work here as an alternative because that really is a property.

What might work fine if you're not dynamically generating the page is if you use the id itself as a variable holding a reference to the page in question (since I think that's how it is handled in QML). So instead of my variant property chart_page, you could probably say just Application.menuEnabled = Boolean(page != yourPageId).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.