Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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();
    }
  }
— asked October 14th 2010 by Chris Schultz
  • ipad
  • orientation
  • popover
0 Comments

8 Answers

  • Why are you testing isPopover as a string literal? Wouldn't you want to say if (isPopover == true) ?

    — answered October 14th 2010 by John McKnight
    permalink
    1 Comment
    • sorry didn't mean for that to have '' around it. It is isPopover == true

      — commented October 14th 2010 by Chris Schultz
  • Why bother testing? Just make it so…just remove the conditional check and hide the popover no matter what

    — answered October 14th 2010 by Duncan Kabinu
    permalink
    0 Comments
  • Still wont hide it. =/

    — answered October 14th 2010 by Chris Schultz
    permalink
    0 Comments
  • 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);
    
    — answered October 14th 2010 by John McKnight
    permalink
    0 Comments
  • 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?

    — answered October 14th 2010 by Chris Schultz
    permalink
    0 Comments
  • 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();
    
    — answered October 14th 2010 by Chris Schultz
    permalink
    0 Comments
  • 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.

    — answered October 14th 2010 by John McKnight
    permalink
    2 Comments
    • I filed a ticket in lighthouse for the hide method.

      — commented October 14th 2010 by John McKnight
    • I really appreciate you doing that. Thanks a lot.

      — commented October 14th 2010 by Chris Schultz
  • 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});
    
    — answered October 14th 2010 by John McKnight
    permalink
    2 Comments
    • Yeah, I tried this as well with no luck.

      — commented October 14th 2010 by Chris Schultz
    • Yup, that's why I filed a bug report. It clearly isn't working the way it should.

      — commented October 14th 2010 by John McKnight
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.