Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11285] iOS: Textfield.blur is having a strange race condition when blurring a textfield and then opening a window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-10-18T22:10:10.000+0000
Affected Version/sRelease 2.1.3
Fix Version/sRelease 2.1.4, Release 3.0.0, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21
ComponentsiOS
LabelsSupportTeam, api, qe-port, regression
ReporterMauro Parra-Miranda
AssigneeVishal Duggal
Created2012-10-06T00:15:47.000+0000
Updated2012-11-01T19:02:35.000+0000

Description

Problem

If you execute blur and then open a window, looks like the blur never happened. If you run an example with Kitchensink, the blur will work as expected. It's like there is a race condition between the execution of the blur in the textfield and the open of the window, where the window opening will take precedence.

Actual Results

The textfield never gets the blur command, when followed by a window opening.

Expected results

The textfield should blur, then the window should open.

Test case

1. Copy this code to an app.js:
// 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 : 'Win 1',
	backgroundColor : '#fff'
});
var productTF1 = Ti.UI.createTextField({
	borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
	top : 100,
	width : 250,
	height : 40,
	hintText : "Add Product..."
});
productTF1.addEventListener("focus", function() {
	Ti.API.info("focus");
	productTF1.blur();
	var win2 = Titanium.UI.createWindow({
		title : 'Win 2',
		backgroundColor : '#fff'
	});
	var close_bttn = Titanium.UI.createButton({
		title : "Close",
		top : 10
	});
	close_bttn.addEventListener('click', function() {
		productTF1.blur();
		win2.close();
	});
	win2.add(close_bttn);
	var data = [];
	var tableView = Ti.UI.createTableView({
		data : data,
		top : 100
	});
	win2.add(tableView);
	tab1.open(win2);
});
win1.add(productTF1);

var tab1 = Titanium.UI.createTab({
	icon : 'KS_nav_views.png',
	title : 'Tab 1',
	window : win1
});
tabGroup.addTab(tab1);

// open tab group
tabGroup.open();
2. Now run the code with 2.1.3.GA on iOS 4.x. 3. If you click on the textfield, the window will open. Close the window, the textfield shouldn't be focused.

Extra info.

This is a regression. This used to work just fine with TiSDK 2.1.3.v20120915120319, now with 2.1.3.GA is broken.

Comments

  1. Ingo Muschenetz 2012-10-09

    Note backport request to 2_1_X branch.
  2. Blain Hamon 2012-10-09

    Wait, what? They're trying to blur in the midle of a focus event? Why even have the text field in the first place? How is this even a valid use case?
  3. Mauro Parra-Miranda 2012-10-10

    Hello, I'm talking with the customer, so I can provide a workaround onto this. BEst, Mauro
  4. Gavin Harriss 2012-10-10

    I wonder if this is related to the issue I'm having: TC-1362
  5. Vishal Duggal 2012-10-11

    Not related to TC-1362. This is a race condition issue.
  6. Vishal Duggal 2012-10-18

    There is a behavior difference in the platform. The developer should never have to call blur when opening a new window. Test Case below. 1. Set inTab to true and notice that returning to previous window brings up the keyboards 2. Set inTab to false and notice that the keyboard remains hidden.
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
       var opened = false; 
       var inTab = false;
       // create tab group
       var tabGroup = Titanium.UI.createTabGroup();
        
       //
       // create base UI tab and root window
       //
       var win1 = Titanium.UI.createWindow({
           title : 'Win 1',
           backgroundColor : '#fff'
       });
       var productTF1 = Ti.UI.createTextField({
           borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
           top : 100,
           width : 250,
           height : 40,
           hintText : "Add Product..."
       });
       productTF1.addEventListener("focus", function() {
           Ti.API.info("focus");
       	if (opened == true) {
       		return;
       	}
       	opened = true;
           var win2 = Titanium.UI.createWindow({
               title : 'Win 2',
               backgroundColor : '#fff'
           });
           var close_bttn = Titanium.UI.createButton({
               title : "Close",
               top : 10
           });
           close_bttn.addEventListener('click', function() {
               win2.close();
           });
           win2.add(close_bttn);
           var data = [];
           var tableView = Ti.UI.createTableView({
               data : data,
               top : 100
           });
           win2.add(tableView);
       	if (inTab == true) {
       	    tab1.open(win2);
       	}
       	else {
       		win2.open();
       	}
       });
       win1.add(productTF1);
        
       var tab1 = Titanium.UI.createTab({
           icon : 'KS_nav_views.png',
           title : 'Tab 1',
           window : win1
       });
       tabGroup.addTab(tab1);
        
       // open tab group
       tabGroup.open();
       
  7. Vishal Duggal 2012-10-18

    Pull pending https://github.com/appcelerator/titanium_mobile/pull/3285
  8. Vishal Duggal 2012-10-18

    3_0_X backport https://github.com/appcelerator/titanium_mobile/pull/3292 2_1_X backport https://github.com/appcelerator/titanium_mobile/pull/3293
  9. Natalie Huynh 2012-11-01

    Tested with 2.1.4.v20121030173408 on iPhone 4s 6.0

JSON Source