Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12147] iOS: regression: button created in require()d unit won't fire click event

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-01-14T17:14:23.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.0.2, Release 3.1.0, 2013 Sprint 01 API, 2013 Sprint 01, 2013 Sprint 02
ComponentsiOS
Labelsdefect, ios, module_require, parity, qe-testadded, regression, titanbeta
ReporterShawn Lipscomb
AssigneeVishal Duggal
Created2012-12-20T23:10:00.000+0000
Updated2013-01-24T10:16:07.000+0000

Description

Problem

There is a regression in SDK 3.0.0.GA that prevents a button's click event from firing when the button is created in a require()d unit. Works in SDK 2.1.4.GA Broken in SDK 3.0.0.GA Note that this works fine on Android under SDK 3.0.0.GA (and SDK 2.1.4.GA)...the problem only exists on iOS.

Testcase

Run the following code and click the button. A console message should appear when the button is clicked, and the button's title should change to "Clicked!", but under SDK 3.0.0.GA this does not happen. Note that this testcase is reduced down to the smallest reproducable code from a very large app. {panel:title=app.js}
var win1=Ti.UI.createWindow({url:'win1.js',
                             fullscreen:false,
                             navBarHidden:false});
win1.ButtonMaker=require('ButtonMaker');
win1.open();
{panel} {panel:title=win1.js}
var MainWin=Ti.UI.currentWindow;

var ButtonMaker=MainWin.ButtonMaker;

function NewButtonClick(evt)
{
  Ti.API.info('Button was clicked');
  Button1.title='Clicked!';
}
var Button1=ButtonMaker.NewButton(MainWin,'Click Me',NewButtonClick);
{panel} {panel:title=ButtonMaker.js}
exports.NewButton=function(Parent,Caption,ClkEvent)
{
  var AButton=Ti.UI.createButton({title:Caption,
                                  width:'122dp',
                                  height:'44dp'
                                 });
  Parent.add(AButton);
  AButton.addEventListener('click',ClkEvent);
  return AButton;
};
{panel}

Comments

  1. Max Stepanov 2012-12-20

    Shawn, did you notice the following warning?
       [WARN] Creating [object TiUIButton] in a different context than the calling function.
       
    Change win1.js code to require module from there, and it will work.
       var MainWin=Ti.UI.currentWindow;
       
       var ButtonMaker=require('ButtonMaker');
       
       function NewButtonClick(evt)
       {
         Ti.API.info('Button was clicked');
         Button1.title='Clicked!';
       }
       var Button1=ButtonMaker.NewButton(MainWin,'Click Me',NewButtonClick);
       
  2. Shawn Lipscomb 2012-12-21

    Max, yes I noticed that warning. In the past (pre 3.0 SDK) we've received that warning with no detrimental effect. We've been using require() like in my example for a year and a half now with many apps dedicated to our CommonJS framework. Moving all of our require() statements into every unit is not a practical solution for us. There are dozens of them with complex relationships (units that require units that require units). The example I gave is a significantly reduced bit of code to make it easy to see the problem. My code works fine in Android. It works fine in SDK 2.1.4. Something in 3.0.0 caused a regression. Please see if this can be addressed. Thanks.
  3. Ingo Muschenetz 2012-12-22

    Shawn--we'll be fixing this the next sprint, which should hopefully be in time for your application deployment (though you will need an unofficial build).
  4. Shawn Lipscomb 2013-01-02

    Thanks, Ingo...looking forward to it.
  5. Vishal Duggal 2013-01-07

    Pull pending https://github.com/appcelerator/titanium_mobile/pull/3668
  6. Blain Hamon 2013-01-14

    Pull merged.
  7. Shawn Lipscomb 2013-01-16

    Any chance of this being merged into the 3.0.1 SDK?
  8. Ingo Muschenetz 2013-01-16

    @Vishal--I added a backport request. Can we see if this can be addressed?
  9. Vishal Duggal 2013-01-16

    backport PR https://github.com/appcelerator/titanium_mobile/pull/3718 Related JIRA ticket is TIMOB-12299
  10. Shyam Bhadauria 2013-01-18

    Now the button is changed to 'Clicked' and console message also appears. Environment used for verification - -iOS 6.0 (simulator) -Mac OSX 10.8 -Titanium Mobile SDK 3.1.0.v20130114171802 -Titanium Studio 3.0.1.201212181159
  11. Shawn Lipscomb 2013-01-18

    Verified fixed in SDK 3.1.0.v20130114171802. Thanks!
  12. Shawn Lipscomb 2013-01-23

    Also verified fixed in SDK 3.0.2.v20130122172624.

JSON Source