Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-12398

Android: TabGroup activity should work like Window activity

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Low
    • Resolution: Cannot Reproduce
    • Affects Version/s: Release 3.0.2, Release 3.1.0
    • Fix Version/s: None
    • Component/s: Android
    • Labels:
      None
    • Environment:

      Ti SDK 3.0.2.v20130123110204.
      Android 4.0.3 emulator.

    • Story Points:
      0
    • Sprint:
      2018 Sprint 25

      Description

      With Windows, it's possible to create menus before opening the window, by assigning Window.activity.onCreateOptionsMenu.

      var win = Ti.UI.createWindow({
        fullscreen: true
      });
       
      var activity = win.activity;
       
      activity.onCreateOptionsMenu = function(e){
        var menu = e.menu;
        var menuItem = menu.add({ title: "Item 1" });
        menuItem.icon = "item1.png";
        menuItem.addEventListener("click", function(e) {
          Ti.API.debug("I was clicked");
        });
      };
       
      win.open();
      

      For a TabGroup, although TabGroup.activity is now exposed, you cannot assign an onCreateOptionsMenu function until after the TabGroup is opened. The following code demonstrates the issue:

      var tabGroup = Titanium.UI.createTabGroup();
       
      var win1 = Titanium.UI.createWindow({
      	title : 'Tab 1',
      	backgroundColor : '#fff'
      });
      var tab1 = Titanium.UI.createTab({
      	icon : 'KS_nav_views.png',
      	title : 'Tab 1',
      	window : win1
      });
      var addMenu = function() {
      	tabGroup.activity.onCreateOptionsMenu = function(e) {
      		var menu = e.menu;
      		var menuItem = menu.add({
      			title : "Item 1"
      		});
      		menuItem.icon = "item1.png";
      		menuItem.addEventListener("click", function(e) {
      			Ti.API.debug("I was clicked");
      		});
      	};
      }
      addMenu(); // To work around issue, comment out this line and 
                 // uncomment the addEventListener call below.
      /*
      tabGroup.addEventListener("open", function() {
      	addMenu();
      	tabGroup.activity.invalidateOptionsMenu();
      });
      */
      tabGroup.addTab(tab1);
      tabGroup.open();
      

      As written, it doesn't add a menu item. If you comment out the standalone addMenu call and uncomment the addEventListener call, the menu item is added as expected.

      Expected Results:

      Menu item is added as on a Window, without needing to add an open event listener or call invalidateOptionsMenu.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                aevans Arthur Evans
              • Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-15406
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code