[TIMOB-16351] Android: addEventListener via call()/apply() fails with exception
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Medium |
| Status | Closed |
| Resolution | Invalid |
| Resolution Date | 2018-01-03T02:39:51.000+0000 |
| Affected Version/s | Release 3.2.0 |
| Fix Version/s | n/a |
| Components | Android |
| Labels | andoid |
| Reporter | Manojkumar Murugesan |
| Assignee | Maggie Chen |
| Created | 2014-01-29T11:47:38.000+0000 |
| Updated | 2018-01-03T02:39:51.000+0000 |
Description
I'm using this widget https://github.com/hoyo/net.hoyohoyo.iconiclabel where they are getting reference of (https://github.com/hoyo/net.hoyohoyo.iconiclabel/blob/master/app/widgets/net.hoyohoyo.iconiclabel/controllers/widget.js) some list of functions / properties and export them. When I use addEventListener it crashes on Android but works fine on iOS.
This is similar to TIMOB-9560 but on Android.
[~mano_mykingdom] I used the addEventListener method on Android Galaxy S3 and its not crashing. I am using the following test scenario's.
If you are doing something different, please attach a simple and runnable test case so that we can reproduce the issue.var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); var al = win.addEventListener; // test 1 //al.call(win, 'click', function(e) { alert('clicked window'); }); // test 2 //al.apply(win, ['click', function(e) { alert('clicked window'); }]); // test 3 //Ti.UI.createWindow().addEventListener.call(win, 'click', function(e) { alert('clicked window'); }); // test 4 //Ti.UI.createWindow().addEventListener.apply(win, ['click', function(e) { alert('clicked window'); }]); win.open();I'm using like this. It crashes on Android but fine with iOS.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); var al = win.addEventListener; al('click', function(e) { alert('clicked window'); }); win.open();Moving this ticket to engineering as I can reproduce the issue with the provided code. Note that this is a valid scenario as per ticket TIMOB-9560 and it works fine for iOS platform.
Not only addEventListener but all the methods it seems. I tried the below one it works on iOS and fails on Android.
var lbl = Ti.UI.createLabel({ text: "Appcelerator", visible : false }); var visible = lbl.setVisible; visible(true);There is a reason for this kind of use case, for example when I have a label / button in a widget and want to access the methods of that object from a controller where it is included. Have a look here https://github.com/hoyo/net.hoyohoyo.iconiclabel/blob/master/app/widgets/net.hoyohoyo.iconiclabel/controllers/widget.js at line no. 320
I don't think this is a bug. Assigning lbl.setVisible to a variable will detach the method from the lbl and needs to be bound again before calling it. Something like var visible = lbl.setVisible; var boundVisible = visible.bind(lbl); boundVisible(true);
3.4.0 is moved forward, and 3.5.0 is taking its place in the calendar.
Issue reproduces Titanium SDK version 3.4.0 master, 3.2.0.GA Titanium Studio, build: 3.3.0.201407100905 Titanium Command-Line Interface CLI version 3.3.0, Android device : Motorola Moto G, Android version : 4.4.4 iOS simulator : iPhone Retina (3.5-inch), iOS 7.0.3
Unable to reproduce with the code as follows. The exception can be avoided through the following code:
orvar win = Ti.UI.createWindow({ backgroundColor: '#fff' }); var al = win.addEventListener('click', function(e) { alert('clicked window'); }); win.open();var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); var al = win.addEventListener; // test 1 //al.call(win, 'click', function(e) { alert('clicked window'); }); // test 2 al.apply(win, ['click', function(e) { alert('clicked window'); }]); win.open();