Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17367] iOS: rightNavButtons and leftNavButtons touch events don't work

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-02-20T18:57:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0
ComponentsiOS
Labels3.3.0, ios, leftNavButton, qe-4.0.0, rightNavButton
ReporterShuo Liang
AssigneePedro Enrique
Created2014-07-06T14:00:28.000+0000
Updated2015-04-02T17:44:14.000+0000

Description

Try code below. The events work twice and then no longer function. index.xml:
<Alloy>
	<TabGroup>
		<Tab title="Tab 1" icon="KS_nav_ui.png">
			<Window title="Tab 1" id="win1">
				<Label>I am Window 1</Label>
			</Window>
		</Tab>
		<Tab title="Tab 2" icon="KS_nav_views.png">
			<Window title="Tab 2">
				<Label>I am Window 2</Label>
			</Window>
		</Tab>
	</TabGroup>
</Alloy>
index.js:
var leftNav1 = Ti.UI.createLabel({
	text: 'tch',
	height: 30,
	width: Ti.UI.SIZE
});
leftNav1.addEventListener('touchstart', function() {
	alert ('left touch');
});

var leftNav2 = Ti.UI.createLabel({
	text: 'clk',
	height: 30,
	width: Ti.UI.SIZE
});
leftNav2.addEventListener('click', function() {
	alert ('click left');
});

$.win1.leftNavButtons = [leftNav1, leftNav2];

var rightNav1 = Ti.UI.createLabel({
	text: 'tch',
	height: 30,
	width: Ti.UI.SIZE
});
rightNav1.addEventListener('touchstart', function() {
	alert ('right touch');
});

var rightNav2 = Ti.UI.createLabel({
	text: 'clk',
	height: 30,
	width: Ti.UI.SIZE
});
rightNav2.addEventListener('click', function() {
	alert ('right click');
});

$.win1.rightNavButtons = [rightNav1, rightNav2];

$.index.open();

Comments

  1. Shuo Liang 2014-07-07

    Tested with regular app for rightNavButtons and leftNavButtons, they all work well. So this problem only happens in Alloy project.
  2. Mark Mokryn 2014-07-07

    FYI - the Alloy version for me is 1.4.0-rc4 (also fails with 1.3.1), and indeed it fails with the XML above. Very strange as the affected elements are not even in the XML (thus I'm not sure the root cause is inside Alloy). The Classic version below works fine for me:
       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 win2 = Titanium.UI.createWindow({  
           title:'Tab 2',
           backgroundColor:'#fff'
       });
       var tab2 = Titanium.UI.createTab({  
           icon:'KS_nav_ui.png',
           title:'Tab 2',
           window:win2
       });
       
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
       
       var leftNav1 = Ti.UI.createLabel({
           text: 'tch',
           height: 30,
           width: Ti.UI.SIZE
       });
       leftNav1.addEventListener('touchstart', function() {
           alert ('left touch');
       });
        
       var leftNav2 = Ti.UI.createLabel({
           text: 'clk',
           height: 30,
           width: Ti.UI.SIZE
       });
       leftNav2.addEventListener('click', function() {
           alert ('click left');
       });
        
       win1.leftNavButtons = [leftNav1, leftNav2];
        
       var rightNav1 = Ti.UI.createLabel({
           text: 'tch',
           height: 30,
           width: Ti.UI.SIZE
       });
       rightNav1.addEventListener('touchstart', function() {
           alert ('right touch');
       });
        
       var rightNav2 = Ti.UI.createLabel({
           text: 'clk',
           height: 30,
           width: Ti.UI.SIZE
       });
       rightNav2.addEventListener('click', function() {
           alert ('right click');
       });
        
       win1.rightNavButtons = [rightNav1, rightNav2];
       tabGroup.open();
       
  3. Mark Mokryn 2014-07-07

    It's an object management bug of some sort. If instead of "var rightNav1" for example I use Alloy.Globals.rightNav1, so it cannot be garbage collected, it works correctly. Thus this may have much further implications than just nav bar buttons.
  4. Mark Mokryn 2014-07-07

    @Tim - how can this be scheduled for 1.5.0? This is a killer bug with no good workaround..... I'm also not convinced it's an Alloy issue - could be just that Alloy manifests it. And if it is an Alloy bug, then it could possibly occur on other elements as well, since no XML is involved here.
  5. Tim Poulsen 2014-07-07

    [~mokesmokes] We're way past code freeze for 1.4 (and SDK 3.3.0), which is why I assigned the 1.5 fix version label. In reality, there will likely be a 1.4.1 (and 3.3.1) which would come out long before an actual 1.5. I'll bring this ticket up at our triage meeting.
  6. Mark Mokryn 2014-07-07

    I hear ya, but this kills really basic functionality just because a project uses Alloy..... I 100% agree with the "Critical" label, and this seems like a critical bug.
  7. Tim Poulsen 2014-07-08

    It's not clear to me why the touch/click events are lost after two events. I see nothing obvious in the generated code that would explain why the events work twice, then stop. Regardless, there are three workarounds: 1) Define your buttons as properties of the $.win object
       $.win1.leftNav1 = Ti.UI.createLabel({
           text: 'tch',
           height: 30,
           width: Ti.UI.SIZE
       });
       $.win1.leftNav1.addEventListener('touchstart', function() {
           alert ('left touch');
       });
        
       $.win1.leftNav2 = Ti.UI.createLabel({
           text: 'clk',
           height: 30,
           width: Ti.UI.SIZE
       });
       $.win1.leftNav2.addEventListener('click', function() {
           alert ('click left');
       });
        
       $.win1.leftNavButtons = [$.win1.leftNav1, $.win1.leftNav2];
       
    2. As a variation of option 1, you can brute force add all the objects to the $.win1 object by adding this line right before your $.index.open() statement: _.extend($, $.win1); (I prefer option 1 to this sledgehammer approach.) 3. Use the development version of Alloy (see the "bleeding edge" installation instructions at https://github.com/appcelerator/alloy/) which includes a fix for ALOY-984. That appears to not have the same problems as the code you're using.
  8. Mark Mokryn 2014-07-08

    Thanks Tim. I also pored over the generated code and saw nothing unusual. My hunch is that the bug is actually not an Alloy bug, but rather in the SDK, and for some reason the garbage collector kicks in earlier when running the generated code. The bleeding edge Alloy version may mask this bug, but the issue is still there, and who knows - maybe after enough events it will also stop working in the regular Titanium code? I still think this warrants a serious investigation by the team - including the SDK team. For example - maybe the bug is here? https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUIWindowProxy.m#L573 (which raises another pain point - why the Titanium iOS SDK is not using Automatic Reference Counting..... that would clear a ton of bugs for sure.....) Thanks again!
  9. Tim Poulsen 2014-07-08

    Since we have a workaround, I'm taking out of this sprint. We'll investigate more to uncover the root cause.
  10. Mark Mokryn 2014-07-08

  11. Tim Poulsen 2014-07-22

    I tried this again with the release versions: Alloy 1.4.0 and SDK 3.3.0.GA (actually tried with our dev branch, 3.4.0 also). If I do a normal "Run on Simulator" build, buttons stop reacting after four events. If I do a "Debug in Simulator" build, buttons keep on reacting (I stopped clicking after 15 clicks). I don't believe this to be an Alloy bug, but something with the SDK itself.
  12. Mark Mokryn 2014-07-22

    I have the same hunch as you Tim. I suspect something is being released in the SDK, when it shouldn't. Which is why when the buttons are attached to other objects (e.g. workarounds 1 & 2 above) the bug doesn't occur.
  13. Tim Poulsen 2015-02-02

  14. Pedro Enrique 2015-02-18

    PR: https://github.com/appcelerator/titanium_mobile/pull/6651
  15. Pedro Enrique 2015-02-19

    new PR: https://github.com/appcelerator/titanium_mobile/pull/6654
  16. Mark Mokryn 2015-02-20

  17. Eric Wieber 2015-03-05

    Verified fixed, using: Titanium SDK 4.0.0.v20150303161012 Studio 4.0.0.201502171827 CLI 3.4.2-rc4 Xcode 6.2b5 Both click and touch events are firing.

JSON Source