Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1423] iOS: Window focus and blur events fire twice

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T15:25:17.000+0000
Affected Version/sRelease 1.6.0
Fix Version/sSprint 2011-31, Release 1.8.0
ComponentsiOS
Labelsn/a
ReporterJon Clarke
AssigneeBlain Hamon
Created2011-04-15T02:51:57.000+0000
Updated2011-11-05T15:25:17.000+0000

Description

Create a tab bar with a couple of tab buttons.

One of the tab buttons opens a window. This window opens another window with a back button (in example below from a table view). Clicking on the back button, the original window fires a focus event which is fine. However, when the second window is open, if you click the tab button again (NOT the back button) to go back to the original window, the original window's focus event fires, then the blur event, then focus. Only the focus event should fire once!

Code (test2.js doesn't really do anything but is not important here)

// get current window
var win = Titanium.UI.currentWindow;
var data = [{title:'row 1'},{title:'row 2'},{title:'row 3'},{ title:'row 4'}];
var table = Ti.UI.createTableView({data:data, editable:false});


table.addEventListener('click', function(e) {


var newwin = Titanium.UI.createWindow({
    title:'test 2',
    backButtonTitle : 'Back',
    url:'../scripts/test2.js'
});

// open the window in the current tab
Titanium.UI.currentWindow.tabGroup.activeTab.open(newwin,{animated:true});



});
win.addEventListener("focus",function(e) { Ti.API.info('test focus');
table.data = data;



});
win.addEventListener("blur",function(e) { Ti.API.info('test blur');
table.data = [];



});
win.add(table);

Comments

  1. vincent youmans 2011-04-15

    when returning from newwin, is there a way to fire a refresh event on win? I have been trying to do this by calling the "focus" event on win, but it only fires the first time win opens. Not when returning from newwin.

    any ideas?

  2. Stephen Tramer 2011-04-15

    Preliminary testing indicates this is still valid.

  3. Pedro Enrique 2011-04-15

    A http://developer.appcelerator.com/helpdesk/view/73281#c347631">Helpdesk customer is having the same problem. I'm just confirming that the bug still exist.

    There is also a related problem: tabGroup focus fires three times when opened. Example code:

       var tabGroup = Titanium.UI.createTabGroup();
       
       var win1 = Titanium.UI.createWindow({backgroundColor:'#ccc'});
       var tab1 = Titanium.UI.createTab({window:win1});
       
       var win2 = Titanium.UI.createWindow({backgroundColor:'#fff'});
       var tab2 = Titanium.UI.createTab({window:win2});
       
       tabGroup.addTab(tab1);
       tabGroup.addTab(tab2);  
       
       tabGroup.open();
       
       tabGroup.addEventListener('focus', function(e){
           Ti.API.info(e);
       });
       

    Console:

       [INFO] {
           index = "-1";
           previousIndex = "-1";
           source = "[object TiUITabGroup]";
           type = focus;
       }
       [INFO] {
           index = 0;
           previousIndex = "-1";
           source = "[object TiUITabGroup]";
           tab = "[object TiUITab]";
           type = focus;
       }
       [INFO] {
           index = 0;
           previousIndex = "-1";
           previousTab = "<null>";
           source = "[object TiUITabGroup]";
           tab = "[object TiUITab]";
           type = focus;
       }
       

    iPhone Simulator 4.2
    Ti SDK 1.6 RC1

  4. Miguel Vizcaino 2011-07-07

       var tabGroup = Ti.UI.createTabGroup();
       var win1 = Titanium.UI.createWindow({
           title:'Tab 1',
           backgroundColor:'blue',
           url:'tableviewmainwindow.js'
       });
       tab1 = Titanium.UI.createTab({  
           icon:'KS_nav_views.png',
           title:'Tab 1',
        	window: win1
       });
       var win2 = Titanium.UI.createWindow({
           title:'Tab 1',
           backgroundColor:'blue'
       });
       var tab2 = Titanium.UI.createTab({  
           icon:'KS_nav_ui.png',
           title:'Tab 2',
           window:win2
       });
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
       tabGroup.open();
       
       var win = Ti.UI.currentWindow;
       var tab = Ti.UI.currentTab;
       var data = [];
       var tableView = Ti.UI.createTableView({
       	top:25,
       	left:0,
       	bottom:15,
           backgroundImage:'images/apple.jpg',
       	data:data,
       	backgroundColor:'white',	
       	style: Titanium.UI.iPhone.TableViewStyle.GROUPED
       });
       var logout_title = Ti.UI.createLabel({
       	text: "Logout",
       	color: '#fff',
       	textAlign:'left',
       	left:10,
       	height:'auto',
       	width:'auto',
       	top:10,
       	font:{fontWeight:'bold',fontSize:18}
       });
       var row1 = Ti.UI.createTableViewRow({
       	height:50,
       	fontFamily:'Arial',
       	fontSize:6, color:'#fff',
       	backgroundColor:'#660099'
       });
       row1.add(logout_title);
       row1.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
       row1.className = 'control';
       row1.hasChild = true;
       data[0]=row1;
       tableView.setData(data);
       
       tableView.addEventListener('click', function(e){
       	Ti.API.info('item index clicked :'+e.index);
       	winMsgDetails = Titanium.UI.createWindow({
       		url:'tableviewchildwindow.js',
       		title:'',
       		backgroundColor:'#fff',
       		barColor:'#111',	
       	});
       	winMsgDetails.addEventListener ('focus', function(e)
       	{	
       		alert('Got Focus Child');
       	});
          	tab.open(winMsgDetails, { animated:true });
       });
       win.add(tableView);
       
       win.addEventListener ('focus', function(e) {	
       	alert('Got Focus Main');
       });
       
       var win = Ti.UI.currentWindow;
       var data = [];
       var tableView = Ti.UI.createTableView({
       	top:25,
       	left:0,
           backgroundImage:'/images/apple.jpg',
       	data:data,
       	style: Titanium.UI.iPhone.TableViewStyle.GROUPED
       });
       var logout_title = Ti.UI.createLabel({
       	text: "Off",
       	color: '#fff',
       	textAlign:'left',
       	left:10,
       	height:'auto',
       	width:'auto',
       	top:10,
       	font:{ fontWeight:'bold', fontSize:18 }
       });
       var row1 = Ti.UI.createTableViewRow({
       	height:50,
       	fontFamily:'Arial',
       	fontSize:6,
       	color:'#fff',
       	backgroundColor:'#660099'
       });
       row1.add(logout_title);
       row1.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.NONE;
       row1.className = 'control';
       row1.hasChild = false;
       data[0] = row1;
       tableView.setData(data);
       win.add(tableView);
       

    Associated Helpdesk Ticket

    http://support.appcelerator.com/tickets/APP-953212
  5. Eduardo Gomez 2011-07-28

    Additional info

    Tested with TiSDK 1.7.x and monitored the FOCUS event that is being fired 4 times.

    Tested on

    iPhone Simulator 4.2

    Console output

    {noformat} [INFO] Focus fired [INFO] Focus fired [INFO] Focus fired [INFO] Focus fired {noformat}
  6. Vikramjeet Singh 2011-08-29

    Tested On: Mac OSX Lion TiMob: 1.8.0v20110819142548 TiStud: 1.0.4.201108101535 Devices: iPhone4 version 4.2.10 iPad2 version 4.3.5 iPod 3
  7. Don Thorp 2011-11-05

    Standardizing summary and labels.

JSON Source