Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16351] Android: addEventListener via call()/apply() fails with exception

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2018-01-03T02:39:51.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sn/a
ComponentsAndroid
Labelsandoid
ReporterManojkumar Murugesan
AssigneeMaggie Chen
Created2014-01-29T11:47:38.000+0000
Updated2018-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.

Comments

  1. Ritu Agrawal 2014-01-29

    [~mano_mykingdom] I used the addEventListener method on Android Galaxy S3 and its not crashing. I am using the following test scenario's.
       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();
       
    If you are doing something different, please attach a simple and runnable test case so that we can reproduce the issue.
  2. Manojkumar Murugesan 2014-01-30

    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();
       
  3. Ritu Agrawal 2014-01-31

    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.
  4. Manojkumar Murugesan 2014-01-31

    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);
       
  5. Manojkumar Murugesan 2014-01-31

    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
  6. Sunila 2014-03-26

    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);
  7. Ingo Muschenetz 2014-08-14

    3.4.0 is moved forward, and 3.5.0 is taking its place in the calendar.
  8. jithinpv 2014-09-04

    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
  9. Maggie Chen 2018-01-02

    Unable to reproduce with the code as follows. The exception can be avoided through the following code:
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       var al = win.addEventListener('click', function(e) { alert('clicked window'); });
       win.open();
       
    or
       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();
       

JSON Source