[TIMOB-17367] iOS: rightNavButtons and leftNavButtons touch events don't work
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-02-20T18:57:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 4.0.0 |
Components | iOS |
Labels | 3.3.0, ios, leftNavButton, qe-4.0.0, rightNavButton |
Reporter | Shuo Liang |
Assignee | Pedro Enrique |
Created | 2014-07-06T14:00:28.000+0000 |
Updated | 2015-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();
Tested with regular app for rightNavButtons and leftNavButtons, they all work well. So this problem only happens in Alloy project.
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:
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.
@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.
[~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.
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.
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
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.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!
Since we have a workaround, I'm taking out of this sprint. We'll investigate more to uncover the root cause.
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.
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.
PR: https://github.com/appcelerator/titanium_mobile/pull/6651
new PR: https://github.com/appcelerator/titanium_mobile/pull/6654
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.