Popover won't hide on orientation change
On orientation change (from portrait to landscape) I'm checking to see if a Popover is shown and if so hide it.
When I test this the Popover never hides. What am I doing wrong?
Here is my code:
Ti.Gesture.addEventListener('orientationchange',function(e)
{
if(e.orientation == 3 || e.orientation == 4)
{
if(isPopover == true) //Checks if the popover is showing
{
navPopover.hide();
}
}
8 Answers
-
Why are you testing isPopover as a string literal? Wouldn't you want to say if (isPopover == true) ?
-
Why bother testing? Just make it so…just remove the conditional check and hide the popover no matter what
-
Still wont hide it. =/
-
Is navPopover in scope at the time? Add this to the orientationchange to see if you have access to it. It's possible that navPopover was defined inside a function or some other context and isn't defined by the time the orientationchange occurs.
Ti.API.info(navPopover);
-
Ti.API.info doesn't work for me in 1.4.
But navPopover is defined outside of a function and is called when orientation is in portrait. So is it possibale that when going from portrait to landscape it becomes undefined?
-
Here is a snippet of code that can be used to see the issue I'm having.
var masterWindow = Ti.UI.createWindow ({ backgroundColor:'#000' }); var navButton = Ti.UI.createButton({ title:'A Button' }); var detailWindow = Ti.UI.createWindow({ backgroundColor:'#fff', top:0, title:'Test', leftNavButton:navButton }); var masterDetail = Ti.UI.iPhone.createNavigationGroup( { window: detailWindow, right:0, top:0 }); masterWindow.add(masterDetail); var navPopover = Ti.UI.iPad.createPopover({ width:320, height:850, navBarHidden:true }); navButton.addEventListener('click', function(){ navPopover.show({view:navButton}); }); Ti.Gesture.addEventListener('orientationchange',function(e) { if(e.orientation == 3 || e.orientation == 4) { navPopover.hide(); } }); masterWindow.open();
-
Your code looks fine. It looks like there is a deeper issue here. If you do this.
Ti.API.info(navPopover.visible);
You don't get true or false, you get NULL in some versions of Titanium.
There are actually a couple bugs. With the most recent builds the app will crash if the popover is visible and the device is rotated. It also refuses to hide a popover when you call the hide method and the visible property doesn't really do what you'd think it would do.
-
I have an addendum. The docs refer to an options parameter which it turns out is not optional. Because you didn't specify options, the call didn't execute as you would expect. I verified this by setting a breakpoint in the Objective-C and found that hide was never called unless I sent options. Now that I send options, the hide method tries to execute however different versions of the API seem to behave in different ways.
BTW - The right call to hide would look like this:
navPopover.hide({animated: true});