Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18075] iOS: Window focus event is not triggered when switch back from another tab

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-12-03T21:24:57.000+0000
Affected Version/sRelease 3.5.0
Fix Version/sRelease 3.5.0, Release 4.0.0
ComponentsiOS
LabelsRegression, module_window, qe-3.5.0, qe-manualtest
ReporterKajenthiran Velummaylum
AssigneeVishal Duggal
Created2014-11-24T08:19:47.000+0000
Updated2014-12-09T23:40:55.000+0000

Description

Window *Focus* Event is not triggered when we switch between tabs in iOS device. For Android, It works fine. This is a *regression* since it doesn't occur in SDK 3.4.1 GA

Steps To Reproduce

1. Create a default titanium classic project 2. Insert following code in your app.js file
win1.addEventListener('focus', function(){
	alert('focused!');
});
3. Run the app in iOS device 4. Switch between *tab 1* and *tab 2*

Expected Result

An alert should appear with text "focused!"

Actual Result

Alert does not appear with SDK version 3.5.0

Tested app.js file

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
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 label1 = Titanium.UI.createLabel({
	color:'#999',
	text:'I am Window 1',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win1.add(label1);
win1.addEventListener('focus', function(){
		    alert('focused!');
		});

//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

var label2 = Titanium.UI.createLabel({
	color:'#999',
	text:'I am Window 2',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});
win2.add(label2);

tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  

tabGroup.open();

Comments

  1. Ingo Muschenetz 2014-12-03

    Look for changes in Window or Tab/TabGroup.
  2. Vishal Duggal 2014-12-03

    This is due to the refactor of alert dialogs and option dialogs for iOS8. Since they are now UIAlertControllers presented modally, the top most window proxy resigns focus when they are presented. We need to ensure that the top most window proxy regains focus on dismissal of Alerts/OptionDialogs
  3. Vishal Duggal 2014-12-03

    The test case above will not work. It will essentially result in an infinite loop on iOS8 since presenting alerts now blurs the window and dismissing it will refocus the window causing the focus event to fire again. Updated test case below
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
        
       // create tab group
       var tabGroup = Titanium.UI.createTabGroup();
        
        
       //
       // create base UI tab and root window
       //
       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 label1 = Titanium.UI.createLabel({
           color:'#999',
           text:'I am Window 1',
           font:{fontSize:20,fontFamily:'Helvetica Neue'},
           textAlign:'center',
           width:'auto'
       });
        
       win1.add(label1);
       
        
       //
       // create controls tab and root window
       //
       var win2 = Titanium.UI.createWindow({  
           title:'Tab 2',
           backgroundColor:'#fff'
       });
       var tab2 = Titanium.UI.createTab({  
           icon:'KS_nav_ui.png',
           title:'Tab 2',
           window:win2
       });
        
       var label2 = Titanium.UI.createLabel({
           color:'#999',
           text:'I am Window 2',
           font:{fontSize:20,fontFamily:'Helvetica Neue'},
           textAlign:'center',
           width:'auto'
       });
       win2.add(label2);
        
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
       
       var lastFocus = null;
       
       win1.addEventListener('focus', function(){
       	//Ti.API.info('WIN1 FOCUS');
       	if(lastFocus != win1) {
       		lastFocus = win1;
       		alert('WIN1 Focus');
       	}
       });
       
       win2.addEventListener('focus', function(){
       	//Ti.API.info('WIN2 FOCUS');
       	if(lastFocus != win2) {
       		lastFocus = win2;
       		alert('WIN2 Focus');
       	}
       });
        
       tabGroup.open();
       
  4. Vishal Duggal 2014-12-03

    Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/6417 3_5_X - https://github.com/appcelerator/titanium_mobile/pull/6418
  5. Wilson Luu 2014-12-09

    Closing ticket as fixed. Verified (using Vishal's test code) focus event is triggered when switching between tabs. Appcelerator Studio, build: 3.4.1.201410281743 SDK build: 3.5.0.v20141208122514 CLI: 3.4.1 Alloy: 1.5.1 Xcode: 6.1.1 GM Devices: iphone 6 plus (8.1.1), ipad air (8.2 beta)

JSON Source